0
我有一個閃亮的應用程序,具有更長的計算取決於輸入。我想知道是否可以在計算完成的同時(而不是之前)在主面板中顯示文本。R有光澤的隱藏mainPanel對象在計算時間
讓我們來舉個簡單的例子。我模擬了長計算與Sys.sleep()
:
# Define UI for application that draws a histogram
ui <- shinyUI(fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
h3('This is an example'),
plotOutput("distPlot")
)
)
))
# Define server logic required to draw a histogram
server <- shinyServer(function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
Sys.sleep(5)
})
})
# Run the application
shinyApp(ui = ui, server = server)
的目標是,以顯示在同一時間計算完成,而不是之前的文本「這是一個例子。」 我認爲我必須使文本以某種方式反應,但到目前爲止我還沒有找到解決方案。也許一個conditionalPanel
可以做到這一點,但我怎樣才能使條件的計算時間?有任何想法嗎?
正是!謝謝 –