【发布时间】:2017-08-08 04:52:15
【问题描述】:
我正在尝试在闪亮的应用程序中动态插入许多图。我已将其简化为一个简单的示例,它显示三个具有相同数量的箱 (48) 的直方图,即使它们应该不同 (16、32、48)。可能我做了一些非常愚蠢的事情,或者错过了一些更微妙的事情!附上代码。提前感谢您的任何建议。
shinyUI(fluidPage(tagList(
actionButton("button_id", "Show plot"),
uiOutput("plot_id"),
HTML("<div id=\"end\">The end</div>"))))
shinyServer(function(input, output) {
# A list to hold the plot IDs
ls <- list()
observeEvent(input$button_id,
{
x <- faithful[, 2]
for (i in 1:3)
{
# generate bins based on input$bins from ui.R
count <- i * 16
bins <- seq(min(x), max(x), length.out = count)
ls[[i]] <<- paste0("plot_", i)
output[[ls[[i]]]] <- renderPlot(hist(x, breaks = bins, col = 'darkgray', border = 'white'))
}
output$plot_id <- renderUI({
wellPanel(do.call(tagList, lapply(ls, function(x)
{
plotOutput(x)
})))
})
})
})
【问题讨论】:
-
我的解决方案有效吗?