r - 根据时间和进度消息自定义闪亮应用程序中的进度指示器
问题描述
我在下面有一个闪亮的应用程序,我想以如下方式自定义此进度指示器:前 10 秒将显示"Analysis running"
,接下来的 10 秒将显示"Still running"
,最后 10 秒显示" Almost there"
。我知道这个情节创建得太快了,但我的原稿需要时间,我想将进度指示器设置为显示 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)
解决方案
推荐阅读
- c# - 在 ASP.NET Core 中配置 return_type 字段
- html - Bootstrap 4 导航栏汉堡无法正确显示,它在移动设备上位于屏幕的一侧
- sql - 如何优化此 SQL Server 查询 - 多个子查询
- c++ - 重载插入运算符
- javascript - 在 useEffect 组件中指定依赖项
- java - RichCoFlatMapFunction 中的不完整/不一致状态
- python - 接收 'KeyError:1' ,为什么会发生这种情况,我该如何解决?
- azure - 用于将数据从 Cosmosdb 推送到 CRM 并执行更新的逻辑应用
- r - R 数据操作 - data.table / dplyr 中的 Rang 条件
- docker - 为什么我不能使用 Docker/VScode 进行远程调试?