I have a reasonably complex Shiny App (several modules) that allows users to fiddle with many different parameters and generate a lot of plots. I want to add the ability for users to download the output they've generated in the Shiny App as a reproducible RMarkdown.
I have read through https://shiny.rstudio.com/articles/generating-reports.html and understand how to do this with a separate Rmarkdown file. However, all of my plotting/data manipulation code is in the Shiny app and it seems like poor practice (violation of DRY) to copy it over to an RMarkdown file -- then any time I want to change the plotting code I would need to change it twice.
What's the correct way to do this so that I don't have to maintain two sets of the same code?