在
shiny
应用程序中,我有一个图,有时需要一些时间来计算。我想用 waiter
包中的进度条来显示此计算的进度。有没有办法将 waitress
应用于 modalDialog
?下面是一个 MWE,其中 waitress
应用于整个页面,但我发现如果我在 modalDialog
上只有一个栏,效果会更好。
我已经从 Demo 检查了可能性:将其应用于
actionButton
在我的实际应用程序中不起作用。将其显示为通知是可行的,但我不知道有什么方法可以在屏幕中央而不是在角落显示通知。我想“元素上”就是我正在寻找的,但我的 modalDialog
没有输入或输出 id。
library(shiny)
library(shinipsum)
library(waiter)
library(plotly)
complicated_function <- function(){
waitress <- Waitress$new(theme = "overlay",min = 0,max = 20)
for(i in 1:20){
waitress$inc(1)
Sys.sleep(0.2)
}
waitress$close()
return(random_ggplotly())
}
ui <- fluidPage(
useWaitress(),
actionButton("plotButton", "Generate Plot")
)
server <- function(input,output,session){
modal1 <- modalDialog(
renderPlotly({
complicated_function()
})
)
observeEvent(input$plotButton,{
showModal(modal1)
})
}
shinyApp(ui, server)
您可以尝试同一包中的 attendantBar:
library(shiny)
library(shinipsum)
library(waiter)
library(plotly)
complicated_function <- function(){
att <- Attendant$new("progress-bar", hide_on_max = TRUE)
for(i in 1:20){
att$set(i * 10)
Sys.sleep(0.2)
}
return(random_ggplotly())
}
ui <- fluidPage(
useAttendant(),
actionButton("plotButton", "Generate Plot")
)
server <- function(input,output,session){
modal1 <- modalDialog(
attendantBar("progress-bar"),
renderPlotly({
complicated_function()
})
)
observeEvent(input$plotButton,{
showModal(modal1)
})
}
shinyApp(ui, server)