How to generate a dynamic UI with more than two selectInput

Hi everyone,
does anyone have some pointer for me about Shiny apps with complex dynamic UI like:
fileInput(xlsx), selectInput(table), selectInput(column), selectInput(analysis) ....
Best regards
Andrea

Hi Andrea,

Could you give us more detail about your needs ?

There is no problem for generating several dynamic UI (input) in a shiny app as long as you give them different inputID.

Aline

1 Like

Yes, it was probably a bit too synthetic.
Imagine you want to have in UI the possibility to

  1. choose an excel file
    2) from the chosen file select a table
    3)from the chosen table select columns
    4) with the chosen columns conduct a certain analysis
    There are here 4 levels of reactivity which are dependent from previous.
    Has anyone an example/template for it like https://shiny.rstudio.com/gallery/dynamic-ui.html but extended on more than 2 levels?
    Best
    Andrea

@zaliani The best way for us to be able to help you is for you to post a minimal example of what you have tried so far, as well as any error messages you are getting, and a small data set that reproduces the problem. You should take a look at the reprex.

The benefit to you posting what you have already tried is people aren't put off by the idea that they are doing the work for you, but rather they see that you have already put in a lot of the work and you just need help fixing specific issues/errors.

As far as what you describe, You can definitely create dynamic ui elements, using renderUI and uiOutput that take reactive values and create inputs with them. A few things that immediately pop into my head as potential issues you will run into with 4 levels of dynamic inputs:

  1. You will likely need to put conditional statements into your renderUI calls so that your app does not fail on launch when a needed object does not exist. You can use validate from the shiny package or you could just use an if statement that looks something like this:
output$render_second_level <- renderUI({
  if (!is.null(input$first_level_input)) {
  #code to generate desired ui
  }
})
  1. choosing a table from an excel file can be tricky, you will want to make sure that all your excel files are going to be consistently formatted or you may run into issues with trying to pull data correctly. You can probably check out the readxl or openxlsx packages for that. If they are just single table excel files or csvs, you are less likely to run into this issue.
2 Likes