{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
module Text.Pandoc.Filter.Plot.Renderers.PlotlyR (
plotlyRSupportedSaveFormats
, plotlyRCommand
, plotlyRCapture
, plotlyRAvailable
) where
import Text.Pandoc.Filter.Plot.Renderers.Prelude
plotlyRSupportedSaveFormats :: [SaveFormat]
plotlyRSupportedSaveFormats = [PNG, PDF, SVG, JPG, EPS]
plotlyRCommand :: OutputSpec -> IO Text
plotlyRCommand OutputSpec{..} = do
exe <- executable PlotlyR oConfiguration
return [st|#{exe} "#{oScriptPath}"|]
plotlyRAvailable :: Configuration -> IO Bool
plotlyRAvailable conf = do
exe <- executable GGPlot2 conf
commandSuccess [st|#{exe} -e 'library("plotly")'|]
plotlyRCapture :: FigureSpec -> FilePath -> Script
plotlyRCapture FigureSpec{..} fname = [st|
library(plotly) # just in case
if (!require("processx")) install.packages("processx")
orca(last_plot(), file = "#{fname}")
|]