英文:
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 <- 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)
答案1
得分: 2
自从这是highcharter绘图的列表(而不是单个highcharter绘图),请使用renderUI
和uiOutput
。
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 <- 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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论