Hello fellow programmers!
I want to show a user a feedback warning for the following scenarios:
- The total number of files uploaded does not equal 23
- The file type is the wrong format
- Both 1 and 2.
I tried using if else
statements but can only get the first one to work.
library(shiny)
library(tools)
library(shinyFeedback)
ui <- fluidPage(
useShinyFeedback(),
fileInput("site",
"Upload .json",
accept = ".json",
multiple = T),
actionButton("submit", "Submit"),
textOutput("validate")
)
server <- function(input, output, session){
validateJSON <- reactive({
json <- input$site
json$filetype <- file_ext(json$datapath)
totalFiles <- nrow(json)
if(totalFiles != 23){
shinyFeedback::feedbackWarning("site",
show = totalFiles != 23,
"Total .json files must equal 23.")
} else if (json$filetype != "json"){
shinyFeedback::feedbackWarning("site",
show = json$filetype != "json",
"Wrong file format! .json files only")
} else if ((totalFiles !=23) & (json$filetype != "json")) {
shinyFeedback::feedbackWarning("site",
show = (totalFiles != 23) & (json$filetype != "json"),
"Wrong file type - 23 total .json files needed.")
}
})
validateWhenClick <- eventReactive(input$submit, validateJSON())
output$validate <- renderPrint(validateWhenClick())
}
shinyApp(ui, server)
Anybody know what I'm doing wrong? Thank you so much!