Giter Site home page Giter Site logo

Is GL screenshot possible about echarty HOT 7 CLOSED

helgasoft avatar helgasoft commented on May 18, 2024
Is GL screenshot possible

from echarty.

Comments (7)

helgasoft avatar helgasoft commented on May 18, 2024 1

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.

helgasoft avatar helgasoft commented on May 18, 2024

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.

Nithador avatar Nithador commented on May 18, 2024

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.

helgasoft avatar helgasoft commented on May 18, 2024

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.

Nithador avatar Nithador commented on May 18, 2024

Perfect! This works and I can proceed from here. Thank You very much for a quick response and help.

from echarty.

rdatasculptor avatar rdatasculptor commented on May 18, 2024

Also there is a way to use webshot2 for this. You can take a look here for some inspiration.

from echarty.

rdatasculptor avatar rdatasculptor commented on May 18, 2024

Neat and quick response! Interesting script, Thanks.

from echarty.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.