0

I'm trying to print my highchartrer chart.

library(highcharter)
webshot::install_phantomjs()
colors_ <- colorize(1:6, c("#FFA500", "#000000"))
df <- data.frame(y = round(rnorm(5, 10, 2), digits = 1),
                 name = paste0("Name", c(1:5)),
                 color = colors_[1:5])

hc <- highchart() %>%
  hc_chart(type = "column") %>%
  hc_xAxis(categories = df$name) %>%
  hc_add_series(
    df,
    dataLabels = list(
      enabled = T,
      shadow = F,
      color = "black",
      style = list(
        textShadow = F,
        textOutline = F,
        fontWeight = 'normal',
        opacity = 1
      )
    )
  ) 

htmlwidgets::saveWidget(widget = hc, file = "hc.html")
webshot::webshot(url = "hc.html", file = "hc.png", delay = 1, zoom = 4, vheight = 500)

This is chart in viewer an html: enter image description here

And this is png or jpg: enter image description here

There are labels, but very transparent. I tried different styles. Without success. Can you help?

installed.packages(): highcharter, htmlwidgets, webshot...

Shen
  • 183
  • 1
  • 10
  • Could you provide the list of all packages you are using? I have many errors when trying to run your code in RStudio by copy/paste. – raf18seb Apr 22 '20 at 11:10
  • Thanks for providing the whole code! The png file is exported correctly in my environment, the dataLabels are black (no additional styles are needed). – raf18seb Apr 23 '20 at 09:16
  • Hm. Bad. I installed new all packages. DataLabels are transparent (( – Shen Apr 23 '20 at 12:25

1 Answers1

2

Instead of using webshot, you should consider to try webshot2 on https://github.com/rstudio/webshot2 which doesn't suffer from this issue. I have replicated your scenario with webshot2, the issue is resolved as below screenshot.

Note: Before trying to install webshot2 package, do not forget to remove websot. In order to remove it, go to the Packages in right bottom corner of Rstudio, sear the package name and click on the adjacent X icon to remove it or you I handle it in this way from the Rstudio console:

remove.packages("webshot", lib="~/R/win-library/3.6")

Code

library(highcharter)
library(webshot2)

colors_ <- colorize(1:6, c("#FFA500", "#000000"))
df <- data.frame(y = round(rnorm(5, 10, 2), digits = 1),
                 name = paste0("Name", c(1:5)),
                 color = colors_[1:5])

hc <- highchart() %>%
  hc_chart(type = "column") %>%
  hc_xAxis(categories = df$name) %>%
  hc_add_series(
    df,
    dataLabels = list(
      enabled = T,
      shadow = F,
      color = "black",
      style = list(
        textShadow = F,
        textOutline = F,
        fontWeight = 'normal',
        opacity = 1
      )
    )
  ) 

htmlwidgets::saveWidget(widget = hc, file = "hc.html")
webshot(url = "hc.html", file = "hc.png", delay = 1, zoom = 4, vheight = 500)

The png file (hc.png)

enter image description here

ozturkib
  • 1,493
  • 16
  • 28
  • I have prepared a blog post including various details about webshot2. You can see the details from http://www.ozturkibrahim.com/export-save-r-graphs-with-webshot/ – ozturkib Apr 28 '20 at 15:29