我无法用你的方法想出一个解决方案。 Shiny
似乎要等到server = function(input, output)
中的所有内容都计算完毕,并且在output$...
的所有组件都可用时才显示结果。我不知道是否有办法解决这个问题。
然而有一个解决方案来实现,你可以尝试:用你的代码Progress indicators
实现:
library(shiny)
shinyApp(
ui = navbarPage(title="test", id="mainNavbarPage",
tabPanel("Input", value="tabinput",
numericInput('n', 'Number of obs', 100),
actionButton(inputId="submit_button", label="Submit")
),
tabPanel("Output", value="taboutput",
plotOutput('plot')
)
),
server = function(input, output, session) {
observeEvent(input$submit_button, {
# Move to results page
updateNavbarPage(session, "mainNavbarPage", selected="taboutput")
withProgress(message = "Computing results", detail = "fetching data", value = 0, {
Sys.sleep(3)
incProgress(0.25, detail = "computing results")
# Perform lots of calculations that may take some time
Sys.sleep(4)
incProgress(0.25, detail = "part two")
Sys.sleep(2)
incProgress(0.25, detail = "generating plot")
Sys.sleep(2)
})
output$plot <- renderPlot({hist(runif(input$n)) })
})
})
这是一个有用的替代,非常感谢你 – explodecomputer
@explodecomputer欢迎您! –