Comments (7)
Thanks @rdatasculptor - good alternative, it works.
#' from https://gist.github.com/dantonnoriega/0744e7537076128ac4a026b8b7f38f09
pp <- cars |> echarty::ec.init()
OUTPUT_HTML <- '~/TEST'
html <- file.path(OUTPUT_HTML, "tstPng.html")
htmlwidgets::saveWidget(pp, file= html, libdir= 'html_files') # save html widget
# make pngs
htmls <- list.files(OUTPUT_HTML, pattern = "html$", full.names = TRUE) # list of all html files
pngs <- lapply(htmls, function(j) { # search folder for html widgets, convert to png
dir <- normalizePath(OUTPUT_HTML)
out <- file.path(dir, gsub("html", "png", basename(j))) # copy name
message(sprintf("Generating... %s", out))
webshot2::webshot(j, file= out, delay=0) #, vwidth=1500, vheight=500, zoom=2)
})
from echarty.
Yes, use toolbox.feature.saveAsImage.
data <- data.frame( # 4+ points needed
x = c(1, 0, 0.6, 0.4),
y = c(1, 2, 0, 2),
z = c(0, 0, 2, 2) )
ec.init(load='3D',
series= list(list(type= 'surface', data= ec.data(data))),
toolbox= list(feature= list(saveAsImage= list(show=T)))
)
from echarty.
Thanks, this shows the button to download png and I need to click it. What I meant was whether there is a way to store a result without human interaction.
From some search I saw, that getDataURL could be used to the instance and save the image. However, I am not sure whether it is possible in R or RStudio, taking an instance from the Viewer pane for example.
Here they describe how this could be achieved in echarts https://stackoverflow.com/questions/43946865/can-i-save-chart-as-image-without-toolbox-interaction-in-echarts
from echarty.
yes, getDataURL is the way to go.
Here is how to do it hands-off with R libraries shiny and png.
library(shiny); library(echarty)
runApp( list(
ui= fluidPage( ecs.output("plot") ),
server= function(input, output, session) {
data <- data.frame(
x = c(1, 0, 0.6, 0.4),
y = c(1, 2, 0, 2),
z = c(0, 0, 2, 2) )
jcode <- "function() {
png = this.getDataURL({pixelRatio: 2, backgroundColor: '#fff'});
if (png.startsWith('data') && png.length>33)
Shiny.setInputValue('png64', png)
}"
output$plot <- ecs.render({
p <- ec.init(load= '3D',
series= list(list(type= 'surface', data= ec.data(data)))
)
# catch moment when image is ready
p$x$on <- list(list(event= 'finished', handler= ec.clmn(jcode) ))
p
})
observeEvent(input$png64, {
tmp <- input$png64
bin <- base64enc::base64decode(what= substr(tmp, 23, nchar(tmp)))
png::writePNG(png::readPNG(bin), "plot.png")
})
}
))
from echarty.
Perfect! This works and I can proceed from here. Thank You very much for a quick response and help.
from echarty.
Also there is a way to use webshot2 for this. You can take a look here for some inspiration.
from echarty.
Neat and quick response! Interesting script, Thanks.
from echarty.
Related Issues (20)
- charts morphing HOT 1
- Combinations of echarts4r and charty HOT 5
- replicate ECharts examples - polar HOT 1
- Method for initializing echart with highlighted series applied? HOT 2
- 1.5.0 causes breaks for all data without rownames or non-numeric keys HOT 3
- Mute visualMap color on specific series elements HOT 7
- Each line a different color using `dataset` option HOT 2
- Error: No handler registered mouseover since v1.5.4 HOT 3
- No handler for mouseover HOT 2
- Compressing sparse bars
- 3d scatterplot animations HOT 1
- Separate symbols/custom shapes | Within timeline frames HOT 1
- Regarding geo plots HOT 5
- An exercise in binding charts | river chart with stacked barplot HOT 8
- Legend issue HOT 3
- Features question HOT 10
- Understanding formatter HOT 3
- Combining pie chart with bar chart HOT 17
- Possible features: Including more information HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from echarty.