Declutter a shiny report’s code v2.0
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
I wrote a year ago on a way to declutter shiny report code which involved putting objects into a source
d 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.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.