Closed svenb78 closed 1 year ago
Have you tried webshot? Take a look here for some inspiration https://gist.github.com/dantonnoriega/0744e7537076128ac4a026b8b7f38f09
I tried webshot myself (since I had a use case as well) but no luck. So if we find a way to export echarts4r plots as an image (e.g. png), this would be most welcome @munoztd0! ,🙂
Echarts has a functionality for this, we can integrate.
Export as images programmatically? (I am aware of the save image feature). This would be brillant!
Ah programmatically, missed that.
Rmarkdown does it, when you use an htmlwidget in a document rendered to PDF.
Maybe something to look at.
Thanks for the replies!
@rdatasculptor : Using webshot
, I get a white 'image' without any graphic. webshot2
needs Chrome, which I don't have available within the respective environment.
Unfortunately, my 'stakeholders' need a Shiny solution. So, an echarts4r
add-on would be great! :-)
Btw.: The echarts4r
library really is great!
You probably get a white image because of the animation.
Set e_animation(show = FALSE)
This works.
library(shiny)
library(echarts4r)
ui <- fluidPage(
tags$head(
tags$script(
HTML("$(() => {
$('#img').on('click', (e) => {
let el = get_e_charts('plot');
let img = el.getDataURL({pixelRatio: 2, backgroundColor: '#fff'});
Shiny.setInputValue('imgstr', img)
})
});")
)
),
tags$a("Save image", id = "img", class = "btn btn-info"),
echarts4rOutput("plot")
)
server <- function(input, output, session) {
output$plot <- renderEcharts4r({
mtcars |>
e_charts(mpg) |>
e_scatter(wt, qsec)
})
observeEvent(input$imgstr, {
str <- input$imgstr
raw <- base64enc::base64decode(what = substr(str, 23, nchar(str)))
png::writePNG(png::readPNG(raw), "plot.png")
})
}
shinyApp(ui, server)
and this doesn't work,:
library(echarts4r)
plot <- mtcars |>
e_charts(mpg) |>
e_scatter(wt, qsec) |>
e_animation(show = FALSE)
htmlwidgets::saveWidget(plot, "plot.html")
webshot::webshot("plot.html", "plot.png")
Again the result is a white image.
Or do I miss something here?
(@JohnCoene was this what you meant by e_animation(show = FALSE))?
Yeah it's an issue form webshot see here
Works well with webshot2 though, @svenb78 is it really impossible to get chrome from your environment ?
webshot2 works! At least for me it does. if it works for you as well @svenb78, then we can close this issue.
@rdatasculptor : I will check and talk to my admin.
John's suggestion works and fits my needs. Many thanks for the help!
I will close the issue.
We should probably document that somewhere, or even provide a wrapper around that download functionality
Hi,
some time ago, I made a shiny app which allows users to export plots -- made with ggplot2 -- into a Word document. I would like to use echarts graphs instead of ggplot, but I don't find a way to export them using a downloadHandler (--> check boxes). I found the
e_toolbox_feature
andsaveAsImage
argument, but that is not what I'm looking for.Can someone help, e.g. with a minimal example for an _echarts4r_toPPTX export function. :-)