loadingButton not disable with shinyjs
Closed this issue · 1 comments
martin-jeremy commented
Hi !
Thank's you for this wonderfull package ! I'm using the loadingButton in a shinyApp and after the first run, i would like to disable the button but it looks like shinyjs::disable() function don't have any effect on it
I try with an observeEvent()
library(shiny)
library(shinyFeedback)
ui <- fluidPage(
fluidRow(
loadingButton('run', 'Run', loadingLabel = 'Running...'),
verbatimTextOutput('finish')
)
)
server <- function(input, output, session) {
observeEvent(input$run, {
output$finish <- renderText('I am running')
Sys.sleep(3)
resetLoadingButton('run')
output$finish <- renderText('I finished my run')
shinyjs::disable('run')
})
}
shinyApp(ui, server)
And also with a reactive value
library(shiny)
library(shinyFeedback)
ui <- fluidPage(
fluidRow(
loadingButton('run', 'Run', loadingLabel = 'Running...'),
verbatimTextOutput('finish'),
verbatimTextOutput('run_once')
)
)
server <- function(input, output, session) {
r <- reactiveValues(run = FALSE)
observeEvent(input$run, {
r$run <- TRUE
output$finish <- renderText({'I am running'})
Sys.sleep(3)
resetLoadingButton('run')
output$finish <- renderText({'I finished my run'})
})
output$run_once <- renderText({ paste("Already run ?", r$run) })
observeEvent(r$run, {
output$run_once <- renderText({ paste("Already run ?", r$run) })
if ( r$run ) {
message('I pass the IF')
shinyjs::disable('run')
message('But my loading button still enabled')
}
})
}
shinyApp(ui, server)
Any idea to disable this button while already pressed ?
phoward38 commented
You need to include shinyjs::useShinyjs()
at the beginning of your UI. It works correctly when included so closing