Declutter a shiny report’s code v2.0

March 3, 2016

(This article was first published on R – It's a Locke, and kindly contributed to R-bloggers)

I wrote a year ago on a way to declutter shiny report code which involved putting objects into a sourced file, however, at that point in time the solution was a bit brittle and clunky. Now there’s a better way to develop shiny applications – shiny modules.

In October, RStudio introduced the concept of modules which involves abstracting code out into self-contained blocks.

Modules are ways of batching your code into discrete chunks – you keep all the code related to the inputs, manipulation, and presentation for doing something in one module. The really neat thing is that you can build modules based on other modules, enabling you to make composite modules or specific modules. Using a module requires you to source the code first to able to use it, but once you’ve done that you can create new instances of the module to suit your needs.

To get started, there is the modules post but beyond that I recommend refactoring one of your existing applications as ameans of learning how best to use them. I did this with my board pack report (stephlocke/Rtraining/inst/apps to mangothecat/boardpack ) and I found it very helpful to work my way through it. I did not find it helpful that I tried to add all sorts of bells and whistles in as I went so I really do recommend giving yourself a smack on the wrist each time you think “oo, I could use XXXX now!” – add features when it becomes easier to do so.

Having used modules, I think they’re a great way to go but I think many R users / developers will struggle with the art of knowing what to put into a module and how to build it for effective usage and future development. With modules we’re really far into the skillset learnt by standard software developers – the art of building classes – and there doesn’t seem to be a lot of help out there because for the most part “it depends”. Putting aside the art of deciding what should be in modules, I think more examples and some Rstudio integration like a shiny modules app project and some code skeletons will really help people get to grips with modules.

Have you tried modules? What was your experience like?

The post Declutter a shiny report’s code v2.0 appeared first on It's a Locke.

To leave a comment for the author, please follow the link and comment on their blog: R – It's a Locke. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)