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

前端 未结 1 895
囚心锁ツ
囚心锁ツ 2020-12-02 03:23

I\'m trying to print my highchartrer chart.

library(highcharter)
webshot::install_phantomjs()
colors_ <- colorize(1:6, c(\"#FFA500\", \"#000000\"))
df <         


        
相关标签:
1条回答
  • 2020-12-02 03:55

    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)

    0 讨论(0)
提交回复
热议问题