R Shiny 使用 Highcharter 的 hw_grid 不起作用

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

R Shiny with Highcharter hw_grid not working

问题

library(highcharter)
library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "hw_grid in shiny", titleWidth = 500),
  dashboardSidebar(width = 150),

  dashboardBody(
    highchartOutput("distPlot")
  )
)

server <- function(input, output) {

  output$distPlot <- renderHighchart({
    charts <- lapply(1:9, function(x) {
      hchart(ts(cumsum(rnorm(100)))
    })
    hw_grid(charts, rowheight = 300)
  })
}

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.

library(highcharter)
library(shiny)
library(shinydashboard)


ui &lt;- dashboardPage(
  dashboardHeader(title = &quot;hw_grid in shiny&quot;, titleWidth  = 500),
  dashboardSidebar(width = 150),

      dashboardBody(
           highchartOutput(&quot;distPlot&quot;)
        )
    )


server &lt;- function(input, output) {

    output$distPlot &lt;- renderHighchart({
      charts &lt;- lapply(1:9, function(x) {
        hchart(ts(cumsum(rnorm(100))))
         })
    hw_grid(charts, rowheight = 300)
      
    })
}

shinyApp(ui = ui, server = server)

答案1

得分: 2

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

ui <- dashboardPage(
  dashboardHeader(title = "hw_grid in shiny", titleWidth  = 500),
  dashboardSidebar(width = 150),
  
  dashboardBody(
    uiOutput("distPlot")
  )
)


server <- function(input, output) {
  
  output$distPlot <- renderUI({
    charts <- lapply(1:9, function(x) {
      hchart(ts(cumsum(rnorm(100))))
    })
    hw_grid(charts, rowheight = 300)
    
  })
}

shinyApp(ui = ui, server = server)
英文:

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

library(highcharter)
library(shiny)
library(shinydashboard)


ui &lt;- dashboardPage(
  dashboardHeader(title = &quot;hw_grid in shiny&quot;, titleWidth  = 500),
  dashboardSidebar(width = 150),
  
  dashboardBody(
    uiOutput(&quot;distPlot&quot;)
  )
)


server &lt;- function(input, output) {
  
  output$distPlot &lt;- renderUI({
    charts &lt;- lapply(1:9, function(x) {
      hchart(ts(cumsum(rnorm(100))))
    })
    hw_grid(charts, rowheight = 300)
    
  })
}

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:

确定