【发布时间】:2017-12-05 15:12:32
【问题描述】:
我正在尝试实现一个闪亮的应用程序,它使用一组参数调用一个函数。这样的函数返回一个用 renderPlot() 渲染的图。会生成一个进度条来让用户保持更新。
我对使用do.call 调用这个函数及其参数特别感兴趣,因为我的最终目标是将它包装成一个闪亮的模块。但是,在有机会生成情节之前,进度条已“完成”。只有在进度条消失后,绘图才会被渲染。我认为这是由于我试图使用do.call() 来处理绘图功能。我在这里创建了问题的简化版本:
ui <- fixedPage(
wellPanel(
plotOutput("plot")
, fluidPage(actionButton("Btn", "plot", class = "btn-primary"))
)
)
server <- function(input, output, session) {
observeEvent(input$Btn, {
message("button triggered")
withProgress(message = "Progress bar"
, detail ='Rendering plot...'
, value = 0,{
# pausa
Sys.sleep(1)
# updade progress bar
setProgress(0.5)
output$plot <- renderPlot({
# plot to render
do.call(plot, list(1:10, 11:20))
# pause
do.call(Sys.sleep, list(2))
})
# update progress to complete status
setProgress(1)
})
showNotification("DONE!", duration = 5, closeButton = TRUE, type = "warning")
})
}
shinyApp(ui, server)
我希望在情节生成和可视化后完成进度条。有什么建议吗?
【问题讨论】:
标签: r progress-bar shiny do.call