TobiSonne
TobiSonne

Reputation: 1107

Conditional action based on file input (shiny)

I have a shiny app in which you can upload an excel sheet. The code is like this:

 fileInput("file1", "Choose file:",
                multiple = FALSE,
                accept = ".xlsx")

Now I want to add another fileInput that is an optional (!) dataset. If I don't choose a file, the first dataset should be as is. If I choose a file, the first dataset should only contain those observations that are not in the optional second dataset based on one variable. Something like Data1[!Var %in% Data2[, Var]]. The only thing I want to know is: How can I formulate the condition if a file is uploaded? Something like if(is_uploaded(input$file2)).

Upvotes: 0

Views: 277

Answers (1)

Stéphane Laurent
Stéphane Laurent

Reputation: 84519

When a file is uploaded, the associated input is not NULL. So you can do

if(!is.null(input$file2))

Upvotes: 1

Related Questions