R 根据时间和进度消息自定义shiny应用程序中的进度指示器
我在下面有一个闪亮的应用程序,我想用这样的方式自定义这个进度指示器:在前10秒,它将显示R 根据时间和进度消息自定义shiny应用程序中的进度指示器,r,shiny,R,Shiny,我在下面有一个闪亮的应用程序,我想用这样的方式自定义这个进度指示器:在前10秒,它将显示“分析正在运行”,在接下来的10秒,它将显示“仍在运行”,在最后10秒,它将显示“几乎在那里”。我知道这个绘图创建得太快了,但我的原始绘图需要时间,我想将进度指示器设置为显示30秒 server <- function(input, output) { output$plot <- renderPlot({ input$goPlot # Re-run when button is cl
“分析正在运行”
,在接下来的10秒,它将显示“仍在运行”
,在最后10秒,它将显示“几乎在那里”
。我知道这个绘图创建得太快了,但我的原始绘图需要时间,我想将进度指示器设置为显示30秒
server <- function(input, output) {
output$plot <- renderPlot({
input$goPlot # Re-run when button is clicked
# Create 0-row data frame which will be used to store data
dat <- data.frame(x = numeric(0), y = numeric(0))
# Create a Progress object
progress <- shiny::Progress$new()
# Make sure it closes when we exit this reactive, even if there's an error
on.exit(progress$close())
progress$set(message = "Analysis running", value = 0)
# Number of times we'll go through the loop
n <- 10
for (i in 1:n) {
# Each time through the loop, add another row of data. This is
# a stand-in for a long-running computation.
dat <- rbind(dat, data.frame(x = rnorm(1), y = rnorm(1)))
# Increment the progress bar, and update the detail text.
progress$inc(1/n, detail = paste("Doing part", i))
# Pause for 0.1 seconds to simulate a long computation.
Sys.sleep(0.1)
}
plot(dat$x, dat$y)
})
}
ui <- shinyUI(basicPage(
plotOutput('plot', width = "300px", height = "300px"),
actionButton('goPlot', 'Go plot')
))
shinyApp(ui = ui, server = server)
服务器