【发布时间】:2022-05-04 16:22:50
【问题描述】:
我有一个复杂的闪亮应用程序,其中包含大量输入、传单地图等...... 我遇到的问题是当应用程序忙于进行一些计算时,用户不断点击应用程序上的任何位置,有时应用程序崩溃。
我想阻止用户在应用程序繁忙时进行任何点击。重要的是微调器保持微调器而不是像waiter 包中的整页服务员。也许有可能将微调器和服务员结合起来?但我还没找到怎么做。
我在这里有一个小代表: 当我单击一个按钮“忙碌的应用程序”时,有一个 5 秒的微调器让用户等待。但在此期间,用户仍然可以点击“增量”按钮。在微调器结束时,输出会按点击次数增加。 我想立即将整个应用程序阻止给用户,而不仅仅是在应用程序繁忙时在按钮上放置“禁用”(因为我的应用程序中有很多输入,并且需要进行太多修改)
library(shiny)
ui <- fluidPage(
# spinner css
tags$head(
tags$style(HTML("
#loadmessage {
position:fixed; z-index:8; top:50%; left:50%; padding:10px;
text-align:center; font-weight:bold; color:#000000; background-color:#CCFF66;
}
.loader {
position:fixed; z-index:8; border:16px solid #999999;
border-top: 16px solid #8B0000; border-radius: 50%;
width: 120px; height: 120px; top:45%; left:45%;
animation: spin 2s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}"))
),
# display load spinner when shiny is busy
conditionalPanel(
condition = "$(\'html\').hasClass(\'shiny-busy\')",
tags$div(class = "loader")
),
actionButton(
inputId = "increment",
label = "Increment"
),
textOutput("result"),
actionButton(
inputId = "busy",
label = "Busy app"
)
)
server <- function(input, output, session) {
rv <- reactiveValues(counter = 0)
#increment counter
observeEvent(input$increment,{
rv$counter = rv$counter + 1
})
#display incremented counter
output$result <- renderText({
rv$counter
})
observeEvent(input$busy, {
Sys.sleep(5)
# during this time, the user should not be able to do anything on the app
})
}
shinyApp(ui = ui, server = server)
【问题讨论】:
-
也许this 可以提供帮助。
-
我看到了,但我正在尝试寻找更全球化的东西,而不仅仅是输入。我有地图、多边形、标记……也可以点击。我在想也许只是在闪亮忙时用一些 JS 禁用左键
-
使用弹出窗口?
-
太干扰了,它会每秒弹出一次。当用户在地图上移动时,地图上会加载数据,因此每秒会弹出一个弹出窗口,持续 0.1 秒