Inside a Shiny App I want to disable all buttons while the app is running. I have a lot of action buttons, dependencies and some renderui stuff, so that I think using shinyjs:disable(button) is crucial and very unclean over 40 and more buttons.
Is there an easy way to disable a button (or all buttons/sliders at once) while the shiny app is busy, like in the condition of the "loading.." element of my example app below?
or is there another way to disable all buttons from being clicked or make them invisible while long computations are running indicated by the "loading.." text?
In my example below I want to disable the action button while the app is busy (the "loading.." text is shown). I know for this example I could use shinyjs but I would prefer an overall solution while the app is busy. Any help is really welcome, I am completely new to html,css and java stuff so if somebody knows a solution to this, a short explanation would be really great!
Many thanks in advance!
library(shiny)
server <- function(input, output) {
output$moreControls <- renderUI({if(input$obs!=10001) actionButton("button", "OK!")})
observeEvent(input$button, {
output$distPlot <- renderPlot({
Sys.sleep(5)
hist(rnorm(isolate(input$obs)), col = 'darkgray', border = 'white')
})})
}
ui <- fluidPage(tags$head(tags$style(type="text/css", "
#loadmessage {
position: fixed;
top: 95%;
left: 0px;
width: 100%;
padding: 5px 0px 5px 0px;
text-align: center;
font-weight: bold;
font-size: 100%;
color: #000000;
background-color: #CCFF66;
z-index: 105;
}
")),
conditionalPanel(condition="$('html').hasClass('shiny-busy')",
tags$div("Loading...",id="loadmessage")),
sidebarLayout( sidebarPanel(
sliderInput("obs", "Number of observations:", min = 10000, max = 100000, value = 10001,step=1000),
uiOutput("moreControls")
),
mainPanel(plotOutput("distPlot"))
)
)
shinyApp(ui = ui, server = server)