Programatically save an eCharts4r chart

78 views Asked by At

I can produce an eCharts4r gauge like

library(echarts4r) library(magrittr)

CA_gauge <- e_charts() %>% 
  e_gauge(4.1, 
          "INCIDENCE", 
          min=0, 
          max=20,
          axisLine = list(
            linestyle = list(
              color=list(
                c(1.5/20, "green"),
                c(3/20, "yellow"),
                c(1, "red")
              )
            ))) %>% 
  e_title("CA")

print(CA_gauge)

But I haven't found a good way to save the output to a file so that I can use it later in a gt table. The best I have been able to find is to add the "saveAsImage" to the output

e_charts() %>% 
      e_gauge(4.1, 
              "INCIDENCE", 
              min=0, 
              max=20,
              axisLine = list(
                linestyle = list(
                  color=list(
                    c(1.5/20, "green"),
                    c(3/20, "yellow"),
                    c(1, "red")
                  )
                ))) %>% 
        e_toolbox_feature(feature = c("saveAsImage"))

That adds a saveAs button in the upper right of the RStudio viewer

enter image description here

But what I'd really like to do is just save the image (obviously without animation) in code to a tiff/jpg/png image file.

I tried using the standard devices like

tiff("CA_gauge.tif",sep=""), 
     res=600, compression = "lzw", height=5, width=15, units="in")
print(CA_gauge)
dev.off()

But that doesn't do it. Any suggestions?

0

There are 0 answers