A few things to take care of while building Shiny apps

Gaurav Chavan
Towards Data Science
5 min readDec 31, 2019

--

Simplified techniques to overcome blockers and save time while building RShiny apps

Ever since the evolution of RStudio in late 2011, Rshiny has been widely adopted to build Dashboards and Apps which have back-end R support and deployment over the web. Embedding CSS and Javascripts functionality into Rshiny apps is possible now with dedicated packages, whose motive is to improve interactivity and provide a dynamic interface. It's been more than 3 years that I have been building and deploying Rshiny apps, so through this blog, I will share some of the hurdles and how to overcome them with simple tips while building the product.

To start with, let me give a brief overview of blocks a beginner/intermediate shiny programmer might face while designing the app.

1. Time spent in design

Aesthetics matter the most as it’s said — “Many things difficult to design prove easy to performance” - Samuel Johnson.

While ShinyDashboard and ShinyDashboardPlus provide templates for designing dashboard, they tend to lack when it comes to providing dynamic UI. For example, Bootstrap Modals fail while using shinydashboard page. To overcome it, designing a dashboard using Bootstrap page is needed, but there you lose your hand on designing as you need to rebuild it from scratch, and it requires a lot of research which utilizes almost 30- 40 % of the total time. For a beginner who has just started designing the app using RShiny may find it draggy.

2. Lack of time for testing — building and testing again

While it seems the app is good to go, suddenly in a demo your app drizzles which indicates an error on console. This error might be due to illogical data manipulation or subset operation which returned zero entries and some times it doesn’t indicate where the error occurred. While you fix the code and make the tool go live again, you see some error which was not taken care of earlier. This happens with me as well.

The reason is that we are so much involved in integrating logic with design, that we hardly get enough bandwidth to handle errors appropriately.

3. Improvise…adapt…overcome challenges

Imagine you wrote a logic for one of the pages in the dashboard and show it to your client. Suddenly, your client asks subtle changes in it which might require you to change the reactivity of the existing tool, and you find yourself in soreness. It happens a lot when the tool you’re designing has multiple modules and you/your client had never thought this upcoming logic which could prove valuable. It adds value to your work, but with the expense of a lot of time in moving back to front again.

Having explained challenges, let’s now focus on how to tackle them.

1. Always follow SDLC { software development life cycle}

Building an RShiny app is a project, and each project has phases in it. While most of us are aware of SDLC, but less are we intended to implement it. Most of the time is spent on designing, leaving no time for testing and integration.

Easy way to understand SDLC | Dignitas Digital

Having a pre-defined SDLC in hand not only helps in software development, but it also helps to keep track of how much time are we putting in each of the phases.

Here is one approach I use before starting the project:

  • Design Wireframe: Always design a Wireframe, which is nothing but a layout of a web page that demonstrates what interface elements will exist on key pages. You can use any tool for that or even design on plain paper will do. Having wireframe in hand will help you determine what ingredients are needed to develop the page, so in return, a lot of time will be saved in implementing aesthetics.

2. Deadlines and workload distribution

While building shiny apps seems to be easy in the beginning, it takes a lot of effort to integrate back-end with front-end. If you are setting deadlines for deployment make sure to:

— Keep test cases in mind to tackle.

— When designing make sure to inspect elements to adjust width and height in the browser itself. Example: Determining appropriate box width or height through little manual tweaks.

Changing Aesthetics on the fly in Rshiny app.

— Separate codes into modules and distribute bandwidth accordingly if the number of pages increases. For example, one page’s front-end code and back-end code will be kept as separate R scripts, which will be imported using source command in Server.R and UI.R. So, if you have a team working on building the app, each person can be utilized for creating a separate module to work with, which can be integrated later on. More info regarding it is mentioned here

— If there is a lot of data to be integrated with the back-end, try to split the code into three parts viz. global.R, Server.R and UI.R, where in global.R will contain only initial data fetching and data cleaning operations.

— If your data import and cleaning take a long time, try to store the initial work-space environment after running global.R as a work-space image (.RData), so that later on, time taken to import it would be reduced, and saved time can be utilized in enhancing UI.

3. Quick catch-up with useful resources

Many concepts will come as new blender while designing shiny apps. Hence, finding the right resource in a short amount of time will prove beneficial. Apart from finding solutions over Stack-overflow, here are few resources which I look forward to while working on RShiny

Asking Questions on GitHub

End Notes

So, after knowing loopholes with recommendations and applying them in your RShiny project, I hope it will help you save an ample amount of time.

Going ahead, I will share a few R tips and Rshiny functionalities which will help you build RShiny apps smoothly and efficiently.

--

--

Explaining problem solving in simplistic ways | Data Science Learner | Blogger