Meh*_*are 2 r shiny shinydashboard
我正在尝试根据矢量的内容将多个框添加到闪亮的界面。
让我们从这里开始:
library(shiny)
ui <- fluidPage(
titlePanel("Dynamic Boxes"),
fluidRow(
uiOutput("boxes")
)
)
server <- function(input, output) {
output$boxes <- renderUI({
interf <- ""
for(i in 1:10){
x = 1:100
interf <- box(title = paste0("box ", i),
renderPlot(plot(x = x, y = x^i)))
}
interf
})
}
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)
它只显示最后一个框。我不知道如何将它们组合在一起,然后将其传递给客户端。
box来自shinydashboard您尚未加载的包(至少在您的帖子中)。无论如何,您需要一个 for 循环不会创建的框元素列表。这是一种方法 -
library(shiny)
library(shinydashboard)
ui <- fluidPage(
titlePanel("Dynamic Boxes"),
fluidRow(
uiOutput("boxes")
)
)
server <- function(input, output) {
output$boxes <- renderUI({
lapply(1:10, function(a) {
x = 1:100
box(title = paste0("box ", a), renderPlot(plot(x = x, y = x^a)))
})
})
}
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)