1. Incorporating Shiny into Dashboards
Up to this point, the dashboards we have built have been static. In this chapter we're going to explore incorporating Shiny into flexdashboards to make them much more dynamic. This is completely optional in your dashboarding process - you can create a flexdahsboard without using Shiny, as we have in previous chapters.
2. Why should I add Shiny? Or not?
Before we get into the details, let's talk about why you might want to use Shiny in your dashboard - or not. The key benefit of incorporating Shiny is providing your dashboard users with a much more interactive experience. Although using htmlwidgets like leaflet provides some level of interactivity, it's limited. Shiny opens up a whole new realm of possibilities for interactivity in dashboards, where the user can make selections with dropdown menus, sliders, and text inputs that change what they see on the dashboard.
3. Why should I add Shiny? Or not?
Another great benefit of using Shiny in flexdashboards is that it brings much of the power of Shiny without as much complication as a full blown Shiny app. We'll talk soon about what a flexdashboard with Shiny actually _is_, but it's not the same as a standard Shiny app, and it can be much simpler.
4. Why should I add Shiny? Or not?
Although incorporating Shiny into a flexdashboard can be more lightweight than building a traditional standalone Shiny app, it is more complicated that the static dashboards we've created to this point. At the very least, it requires thinking about which portions of the dashboard react to which user inputs, and making sure this is still correct as changes are made.
5. Why should I add Shiny? Or not?
Perhaps the most important added complication to note is that Shiny means the dashboard must either be hosted or be run locally by users with R installed. Unlike a static dashboard, which exists as a standalone html file that can be shared or hosted without any R-specific setup, any dashboard involving Shiny requires a connection to R to run. There are multiple ways to achieve this, such as using Shinyapps.io, setting up Shiny Server, purchasing RStudio Connect, or maintaining R installations on users' individual machines. Before incorporating Shiny into your dashboard, consider how you will make the resulting dashboard available to your users, and whether the complication this represents for your particular setup is worth the benefits of added interactivity.
6. If not a Shiny app, then what?
I've mentioned that incorporating Shiny into your flexdashboard is not the same as creating a standalone Shiny app. So if it's not a Shiny app what is it? Just like with our static flexdashboards, it's still an RMarkdown document -- but now it's an _interactive_ RMarkdown document. There are other ways to produce interactive RMarkdown documents that don't involve flexdashboard, but all involve Shiny components. In fact, an interactive RMarkdown document _does_ produce an actual Shiny app. It's just not one that's created in the classic non-RMarkdown way, and instead of appearing in traditional Shiny app form, it takes the form of the type of document it's based on -- in this case a flexdashboard.
7. Making it shiny
So, what actually turns a flexdashboard into a shiny flexdashboard? Just one simple option in the yaml header: runtime: shiny!
8. Let's practice!
Time to try it!