In the app below when the user does not upload a .xls
file I want a pop up to be displayed. Now it appears only in the beginning but if upload another lets say doc
file it is hidden. I do not care it is with shinyalert
package or other method.
library(shiny)
library(shinyalert)
ui <- fluidPage(
useShinyalert(), # Set up shinyalert
fileInput('file1', 'Choose xls file',
accept = c(".xls")
)
)
server <- function(input, output, session) {
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)
}
shinyApp(ui, server)
CodePudding user response:
This also resets the fileInput
:
library(shiny)
library(tools)
ui <- fluidPage(
uiOutput("fileUpload")
)
server <- function(input, output, session) {
showModal(modalDialog("My startup modal..."))
resetFileUpload <- reactiveVal(FALSE)
output$fileUpload <- renderUI({
resetFileUpload() # reactive dependency
resetFileUpload(FALSE)
fileInput('file1', 'Choose xls file', accept = c(".xls"))
})
observeEvent(input$file1, {
if(file_ext(input$file1$name) != "xls"){
resetFileUpload(TRUE)
showModal(modalDialog("That's not a .xls file"))
}
})
}
shinyApp(ui, server)