Home > OS >  Shiny modal that is dependent on fileInput() in shiny app
Shiny modal that is dependent on fileInput() in shiny app

Time:02-08

I have created a modal that is activated when the app is launched and warns the user that he first needs to upload an excel file. But when I upload it the modal is displayed again which seems to be wrong.

library(shiny)
library(shinyalert)

ui <- fluidPage(
  useShinyalert(),  # Set up shinyalert
  fileInput('file1', 'Choose xls file',
            accept = c(".xls")
  )
)

server <- function(input, output, session) {
  observeEvent(is.null(input$file1), {
    # Show a modal when the button is pressed
    shinyalert("Oops!", "Something went wrong.", type = "error")
  })
}

shinyApp(ui, server)

CodePudding user response:

Perhaps you can try with an if condition.

observeEvent(input$file1, {
    if (is.null(input$file1))
    # Show a modal when the button is pressed
    shinyalert("Oops!", "Something went wrong.", type = "error")
  }, ignoreNULL = FALSE)
  •  Tags:  
  • Related