Dynamic generation of plots in Shiny app

Hi there. I'm wondering if there's a way to dynamically generate plots in a Shiny app. I want to generate plots for each column in the dataset uploaded to my app, but I have a critical problem. Depending on the type of data in a column, I create:

  • a bar plot for categorical data
  • for numerical data: histogram, boxplot or density plot.

There are two picker inputs for both categorical and numerical variables. Each plot is in a separate bslib card, for numeric plots there's a select input in the card header, so the user can choose plot type. By default, I generate plots for all categorical and numeric variables, but when I change the set of selected variables in a picker input, all plots for either numeric or categorical variables are generated again. It's very annoying, especially when I pick another plot type for numeric variable, and when I select/deselect numeric var it is generated again in a default type. I'm wondering if there's a way to avoid this, so that when I select a particular var, only one plot is generated or hidden when I deselect a var. Thanks in advance for your help!

Could insertUI() and removeUI() be useful to implementing your idea? Insert and remove UI objects — insertUI You'd have to make sure an insertUI() runs for each plot you need to generate, and you'd probably have to give each bslib card you generate a unique ID so you can target it when calling removeUI.

Wow, I haven't come across these functions before! I'll try to work with them and let you know if it helped, thanks:)