2
votes

this is my first question on StackOverflow. I’ve tried to make it as clear as possible, but I am also very open to feedback!

I am creating an app with R shiny to analyze two dimensional data (Time and Value) for multiple samples.

I would like the application to:

  1. Import the sample files.

  2. Recognize the number of samples in the uploaded files.

  3. Create a selectInput bar for each sample.
  4. Create a ggplot object for each sample.

Huge thank you to Pork Chop for pointing out the similarities to this question - that solved my multiple selectInput bar issue. Also thank you to camille for suggesting purr's map function, that helps me create a list of ggplot objects without fuss.

However, I am still struggling to get all of the ggplot objects to display in Shiny. I have used this approach for inspiration but the author uses a for loop with static length. I tried their approach, just to see if it works, but it also only gives me the first plot of my list of plots.

Here is a very basic example of my current approach. Maybe something with map/lapply with renderPlot? i.e. map(plot_list, renderPlot({})) ?

Sincerest thanks again for your help and patience.

EDIT: finally managed to solve my issue with a lot of help from this post! Instead of using max_plots I created a reactive value for number of samples, and was able to get the plots to display properly once I added observe({}).

1
I'm not very familiar with Shiny, but since R operates over vectors, there's usually a better way than a for loop. For the plots, I would use split to split the data by sample, and then either an apply function or (my preference) one of purrr's map functions. That gets you a list of ggplots. I think you should be able to do something similar for the Shiny inputs. - camille
Thank you Pork Chop for the link - I managed to create a list of radioButton inputs, so that's a great start. I will try to both adapt that solution to my ggplot issue and also try camille's idea. I haven't used purr much, and I will look into it. Thank you both again! - pb_and_ellie

1 Answers

0
votes

As described in the edit I made, this post was extremely helpful. Wrapping the actual creation of the plots in observe({}) and creating a reactive element for number of imported samples was crucial.

Pork Chop's reference to this post solved my issue with multiple dynamic inputs.