简体   繁体   中英

Shiny, show element only if file selected in fileInput

In my Shiny app the user can load up to 4 files. I would like to show a unique ID (found scraping the text in the file) for a given file when the file is loaded by the user. However, since I use reactive functions, I managed to show these unique IDs only if the user load the all 4 files. Here are the lines of code, server side, showing the embedded html piece of program:

tags$li( paste0("ID files : ", code_to_get_ID_file( input_file_1() ),
                               code_to_get_ID_file( input_file_2() ),
                               code_to_get_ID_file( input_file_3() ),
                               code_to_get_ID_file( input_file_4() )
         )
)

In the previous code the input_file_i reactive functions are defined as follows:

input_file_i <- reactive({
    req(input$file_i)
    readLines(input$file_i$datapath)
  })

Do you have any idea on how to proceed in order to show each ID immediately after the user load a given file? Maybe I should use an if statement? If this is the case do you know how/where to put them? Or does exist a specific Shiny function for such a case?

Ok, it was easier that I first thought. I associated a new output with the name of the file, which corresponds also to the unique ID of each file and I rendered it as text:

  output$file_i <- renderText({
  paste("ID file i : ", input$file_i$name)
  })

Finally I added:

  tags$li( textOutput("file_i") )

And everything worked out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM