[UPDATE – December 2020] – A new version of the package was recently released. With it, we decided to write a new article on the library alongside a short interactive tutorial. You can read it here.
In web applications, routing is the process of using URLs to drive the user interface. Routing adds more possibilities and flexibility while building a complex and advanced web application, offering dividing the app into separated sections.
If you’re an avid fan of R Shiny, then the shiny router package provides a solution to your routing problems. In this article, we’ll share what’s new with interactive code examples.
Previously the package was based on the external page.js library. Thanks to the use of a Shiny session object we moved it fully to R.
Separated server for each bookmark
Now each bookmark can be isolated and fully working shiny app. The new feature allows you not only to separate UI for each bookmark – but you may also define its own server now. Just check the below example!
Image 2 – R Shiny app with two routes
How to Pass Parameters to an App using GET URL Variables
Image 3 – Passing parameters
Operating Routing from the Server Side in a shiny router
route_link – function for changing URL for bookmark by adding hashbang (#!) prefix
change_page – function for changing the currently displayed page
get_page – function to extract the “hash” part of the URL
is_page – a function that verifies if the current page was passed successfully.
Image 4 – Server-side routing
Add Stylings to the shiny router with Boostrap and Semantic UI
You can suppress Bootstrap dependency on the specified bookmark. You can switch between Bootstrap and Semantic UI pages or disable styles. This is especially useful when using both Bootstrap and semantic-UI frameworks in one application.
Image 5 – shiny.router stylings
How to Get shiny router
Image 6 – shiny.router logo
The package is available both on R Cran and Github. If you will stumble upon any issues please file them on GitHub where our team will reply. Are you using already our router package in your shiny projects? Say hello to us and share your story – it will help us make our open source better. Look for us at R events and collect our hex stickers!
Further Steps and Future Plans
We are planning to constantly work on the package to make it more versatile. As the next steps, we want to allow passing parameters between separated bookmarks servers and the ability to save the application state. We hope that you will appreciate the improvements we did within the last two years.