我無法用你的方法想出一個解決方案。 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歡迎您! –