How to: add Dark Mode on your Shiny R apps✨#datascience #datavisualization
videoimage: thumbnail.jpg
Transcript#
This transcript was generated automatically and may contain errors.
You can add Dark Mode to your Shiny for R apps in just a few easy steps. Here I have a simple app with a plaque that reacts to a slider input that's in the sidebar of a page sidebar. In order for this to work, you're going to need to use both Shiny and BSLib together, and make sure that you're using one of BSLib's page functions.
Then, inside the sidebar, I'm simply going to add InputDarkMode. Now, when users open your app, InputDarkMode will choose the color scheme that matches their system profile. It also gives them a toggle button where they can switch between light and dark mode.
For most apps, this is all you need. You can stop right here. But in our app, we have a plot, and we would like the plot to match the current color mode. To do that, I'm going to use the thematic package, and simply call thematic on. Thematic will automatically update my ggplot and other types of plots to match the current color mode.
Thematic will automatically update my ggplot and other types of plots to match the current color mode.
For more complicated tasks, I can give InputDarkMode an ID so that I can react to the current color mode on the server. I hope you enjoyed this tip. Go make some beautiful Shiny apps that you can use at night.
