Open slodge opened 1 year ago
For RMarkdown today I've been using chunk code a bit like:
\```{r fig.width=7, fig.height=5}
width <- knitr::opts_current$get("fig.width")
height <- knitr::opts_current$get("fig.height")
plot_counter_private <- 0
plot_counter <- function() {
plot_counter_private <<- plot_counter_private + 1
plot_counter_private
}
png_chart <- iv_api$Create_PNG_Chart_for(params, width = width, height = height)
#this is not a good path... what should we use? How do we get this into the _files folder? :/
#plot_path <- knitr::fig_path("iv_chart.png", knitr::opts_current, plot_counter())
plot_path <- paste0("iv_chart_", plot_counter(), ".png")
png::writePNG(png_chart, plot_path)
knitr::include_graphics(plot_path)
\```
It seems to work... but I've failed (so far) to work out how to do a loop of multiple charts (maybe I have to call child RMDs) and I'd also love to get these generated charts into the "files" knit directory...
Would be good to get some recommended practice here for how to call plumber based PNG/SVG charts and htmlwidgets in order to embed them in RMarkdowns (and soon in Quarto - but right now we've got lots built around RMarkdown and can't move yet)
A helper function or two might also help here - it's a bit ugly that every client markdown has to repeat the width/height/plot code? (Will work on this internally)
Leaving this open for maintainers to decide if/when to implement. Happy for them to close it if required.
I've been trying to explain to people inside my team how we will use Plumber APIs inside our other R code.
So far we've used a fork copy of [https://github.com/bergant/rapiclient] with some auth additions which I think will make R calling plumber APIs pretty straight-forward.
I am, however, struggling a bit with "good practice" when it comes to consuming anything except text and JSON inside e.g. Shiny and RMarkdown.
For example, I've been trying to use a PNG plot output today in a Shiny app. I've coded that into an app which an imageOutput like:
Note: I know this isn't optimal... still plenty to tweak and experiment with - would like to get the file saving direct into the httr::GET ideally... just fighting the rapiclient wrapper
The feature request here is: I think it'd be useful for the plumber docs to have a section on how to make Shiny apps and markdowns that interally use plumber requests for json data, for png's, for svg's and for htmlwidget's...
I also think it might be useful to add some helper functions to some library somewhere too - e.g. most of the above renderImage could be hidden away I think (especially if #897 provides a standard way of specifying image sizes)