R Shiny 使用 Highcharter 的 hw_grid 不起作用

huangapple go评论93阅读模式
英文:

R Shiny with Highcharter hw_grid not working

问题

  1. library(highcharter)
  2. library(shiny)
  3. library(shinydashboard)
  4. ui <- dashboardPage(
  5. dashboardHeader(title = "hw_grid in shiny", titleWidth = 500),
  6. dashboardSidebar(width = 150),
  7. dashboardBody(
  8. highchartOutput("distPlot")
  9. )
  10. )
  11. server <- function(input, output) {
  12. output$distPlot <- renderHighchart({
  13. charts <- lapply(1:9, function(x) {
  14. hchart(ts(cumsum(rnorm(100)))
  15. })
  16. hw_grid(charts, rowheight = 300)
  17. })
  18. }
  19. shinyApp(ui = ui, server = server)
英文:

I want to use hw_grid from highcharter to display various plots in the UI. However, the plots do not show. Here is a sample code. If you run the code outside of shiny it displays the plots but shiny does not.

  1. library(highcharter)
  2. library(shiny)
  3. library(shinydashboard)
  4. ui &lt;- dashboardPage(
  5. dashboardHeader(title = &quot;hw_grid in shiny&quot;, titleWidth = 500),
  6. dashboardSidebar(width = 150),
  7. dashboardBody(
  8. highchartOutput(&quot;distPlot&quot;)
  9. )
  10. )
  11. server &lt;- function(input, output) {
  12. output$distPlot &lt;- renderHighchart({
  13. charts &lt;- lapply(1:9, function(x) {
  14. hchart(ts(cumsum(rnorm(100))))
  15. })
  16. hw_grid(charts, rowheight = 300)
  17. })
  18. }
  19. shinyApp(ui = ui, server = server)

答案1

得分: 2

自从这是highcharter绘图的列表(而不是单个highcharter绘图),请使用renderUIuiOutput

  1. ui <- dashboardPage(
  2. dashboardHeader(title = "hw_grid in shiny", titleWidth = 500),
  3. dashboardSidebar(width = 150),
  4. dashboardBody(
  5. uiOutput("distPlot")
  6. )
  7. )
  8. server <- function(input, output) {
  9. output$distPlot <- renderUI({
  10. charts <- lapply(1:9, function(x) {
  11. hchart(ts(cumsum(rnorm(100))))
  12. })
  13. hw_grid(charts, rowheight = 300)
  14. })
  15. }
  16. shinyApp(ui = ui, server = server)
英文:

Since these are list of highcharter plots (and not a single highcharter plot) use renderUI and uiOutput.

  1. library(highcharter)
  2. library(shiny)
  3. library(shinydashboard)
  4. ui &lt;- dashboardPage(
  5. dashboardHeader(title = &quot;hw_grid in shiny&quot;, titleWidth = 500),
  6. dashboardSidebar(width = 150),
  7. dashboardBody(
  8. uiOutput(&quot;distPlot&quot;)
  9. )
  10. )
  11. server &lt;- function(input, output) {
  12. output$distPlot &lt;- renderUI({
  13. charts &lt;- lapply(1:9, function(x) {
  14. hchart(ts(cumsum(rnorm(100))))
  15. })
  16. hw_grid(charts, rowheight = 300)
  17. })
  18. }
  19. shinyApp(ui = ui, server = server)

R Shiny 使用 Highcharter 的 hw_grid 不起作用

huangapple
  • 本文由 发表于 2023年3月9日 19:13:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75683828.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定