0

I'm having a problem with my shiny app.

My app work with 3 elements:

-radioButtons with 3 choices ('Rachat','Reversement','Résiliation')

-fileInput to choose a csv file

-selectInput that display categories based on the categories that exists in the csv file.

My problem is that I must follow an order so that my app can work (which basically display a table and a graph),the order is: That I must choose one of the choices of the radioButtons first ,then I can choose the file and the categorie so that my table and graph can show up,if for example I choose the csv file first then I pick a choice of the radiobuttons choices nothing shows up.So please how can I solve this problem?

Here's my server function

note:

1-risque is the id of radioButtons

2-produit is the id of selectinput

3-rachat() and reversement() are 2 functions I'm using

server = function(input, output,session) {options(shiny.maxRequestSize=30*1024^5)
    
    
    
    
    
    observeEvent(input$file, {
      
      mytable <- read.csv(input$file$datapath, sep=";")
      
      updateSelectInput(session,"produit", choices = unique(mytable[,"CATEGORIE"])[order(unique(mytable[,"CATEGORIE"]))])
      
    })
    
 
       output$table <- renderTable(df())
       
      df=eventReactive(input$produit,
                       {
                         if (input$risque=='Rachat')
                         {
                           my_data<<-rachat(input$file$datapath,input$produit)[[1]]
                         }
                         if (input$risque=='Reversement')
                         {
                           my_data<<-reversement(input$file$datapath)[[1]]
                         }
                         my_data
                       },ignoreNULL = FALSE)
     
      
   
      output$graphe <- renderPlot(f())
        
      f=eventReactive(input$produit,
                       {
                         if (input$risque=='Rachat')
                         {
                           my_data<<-rachat(input$file$datapath,input$produit)[[2]]
                         }
                         if (input$risque=='Reversement')
                         {
                           my_data<<-reversement(input$file$datapath)[[2]]
                         }
                         my_data
                       },ignoreNULL = FALSE)
      
    
        output$graphe1 <- renderPlot({
          
          graphe(input$file1$datapath)
    
      })
        
        
      
  
  
  • Welcome to SO, please read [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example?rq=1). Several existing posts could help you with this issue, but especially using `req()` could be helpful, see [this](https://stackoverflow.com/questions/50469653/how-to-control-the-order-of-execution-of-the-program-in-shiny) and [this](https://shiny.rstudio.com/articles/req.html). – julien.leroux5 Aug 13 '21 at 09:19

0 Answers0