Mandy
Mandy

Reputation: 129

Shiny reactive check if file is choose

Good morning. I want to check if file is choose or not in fileInput so I had to create reactive function but this not working.

ui.R

        fileInput("file_input","Choose your file in csv")             

        mainPanel("main panel",textOutput("choose"))

server.R

library(shiny)
isFileChoose<-function(){reactive({

  if(is.null(input$file_input))

    return (FALSE)

  else

    return (TRUE)


  })  }


server <- function(input, output) {


 if(isFileChoose()==FALSE)
{
 output$choose<-renderText("Not selected file")

}

 }

Upvotes: 2

Views: 2265

Answers (1)

Florian
Florian

Reputation: 25385

I do not think you can just use a reactive in a function like that, see here. You could do this:

library(shiny)

ui <- fluidPage(
  fileInput("file_input","Choose your file in csv"),            
  textOutput("choose")
)

server <- function(input, output) {

  output$choose <- reactive({
    if(is.null(input$file_input))
    {
      "No input given yet."
    }
    else
    {
      "Now we can process the data!"
    }
  })

}

shinyApp(ui = ui, server = server)

Hope this helps!

Upvotes: 4

Related Questions