DataLabels in R highcharter cannot be seen after print as png or jpg

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...


Solution 1:

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