Rfun - Interactive Dashboards: Visualizations with R's HTMLwidgets and flexdashboards
ฝัง
- เผยแพร่เมื่อ 10 พ.ย. 2024
- LIFECYCLE: SUPERSEDED... With the advent of Quarto, this workshop is superseded by Quarto Dashboards. I strongly recommend using Quarto dashboards rather than following this legacy workshop.
Dashboards with R's HTMLwidgets and flexdashboards packages (and the crosstalk package) enable R coders to generate dashboards with linked reactive widgets (visualizations). Storyboards and even printed posters can be easily generated as well. This workshop provides quick instructions and clear demonstrations for the advanced beginner UseR.
See Demo dashbaord - rfun-flexdashb...
See workshop slides - rfun-flexdashb... Materials available at github.com/lib...
More Rfun at Rfun.library.d...
Part of the DVS Workshop Series: library.duke.ed...
This was very helpful! Had done too many searches to learn how to use Flexdashboards package untill i bumped on this one. Thanks for the video!
Great workshop. I have a doubt what if a shiny app uses external css file. I want to put that in flexdsahboard how can i do it?
You can use CSS with flexdashboards. See: flexdashboard-pkg.netlify.app/articles/theme.html#add-css-styles
Great workshop! Thank you!
37 - 39 minutes playback poorly on my machine.
Thanks for posting this, very informative!
Good workshop as always John. Will build couple of these dashboards for sure. I will have to check whether a normal ggplot object can filter/make connections with other objects in flexdashboards
wonder if you ever used Power Bi and if so would you still use flexdashboards?
Thank you for the kind words, Ahmad.
While a normal ggplot object can easily be displayed in a flexdashboard, that type of visualization will not be reactive to end-user manipulation. Because, a normal ggplot object is not reactive to filters and sliders. However, to effect reactivity in flexdashboards, you only need to use {plotly} [i.e. the ggplotly() function] and {crosstalk} which are introduced around the 8 minute mark of the video, and then expanded upon later in the video.
To answer you other question, I would not use Power Bi. Although Power Bi can also create reactive plots. The trade-off between the two approaches (R/Tidyverse v Microsoft/PowerBI) boils down to which ecosystem you prefer, as well as the affordances of the respective approaches.
One of the values of an R-approach is an open environment. With R (and the Tidyverse) the open environment is portable without a cash investment in software. From a reproducibility perspective, which is foundational for me, the entire R/Tidyverse ecosystem is far more advanced and developed, and carries far less risk of vendor-induced lock-in.
As with all open source approaches there are some trade-offs. Typically the initial learning-curve of open-source approaches is a little higher than proprietary systems such as Microsoft or Tableau. But open-source approaches are often cheaper, more extensible, and more sustainable over time. There are debatable nuances, of course. But I personally don't see Power BI as a competitive substitute for flexdashboards, even though you can accomplish similar outputs. This is especially true for my needs, which include broad shareability, reproducibility, and transparency.
The other comment I would make is that reactivity in the R/Tidyverse/flexdashboards ecosystem can be extended beyond ggplot. For example, many people use the {shiny} environment -- free hosting for shiny apps is available at shinyapps.io. Or more recently with the introduction of Quarto (quarto.org - brought to you by the same people who developed the Tidyverse -- so it all works seamlessly together and is still open-source) you can now generate reactive (interactive) visualizations using the Observable JS stack. As with anything new, of course, there is a learning curve. But with a foundation in R, the effort of adding Observable JS reactivity is certainly manageable. Meanwhile the interactivity of Observable web objects is both stunning and impressive, especially when compared to Power BI and Tableau -- for many of the reasons I've address and other reasons as well.
tl;dr - If I want to add reactivity to a flexdashboard, my first-level approach would start by adding the {crosstalk} and {plotly} packges. Beyond that I would either add {shiny}. Or for a an even more impressive approach I would investigate Quarto (which works in R, Python, Julia, and with tools like VS Code) and Observable JS. (Here's a good introduction to interactivity with R --> quarto.org/docs/interactive.)
Good luck.
@@JohnLittle1 Thank you for the detailed feedback. totally agree with your input. I think i will be spending more time learning about the interactivity especially with Shiny. I will stick with flexdashboards for now as you really explained a lot of good things that make learning flexdashboards as a must for me at this stage.
Hi, how can I change the default color of the tickets on the dashboards from blue to grey when you hover your mouse over it?
Thanks in advance
HI @giulio. You will want to consult the documentation on how to alter the appearance of a dashboard using Themes. Alternatively and/or additionally you can customize the appearance with the CSS Styles. See: rmarkdown.rstudio.com/flexdashboard/using.html#appearance
Hi John thank you for sharing this, may I ask you something, when I want to run your map.
"Leaflet “couldn't infer lng column” but df shows both lat and lng colums loaded"
Hi Tania. Are you working on the index.Rmd file? If not, please let me know the filename that is not working. If possible, provide the line number of the code that is not working.
You may want to make sure all your packages are up to date.
I just ran all the code and it seemed to work fine. But I am happy to take a closer look if you can direct me to a specific file/line-number. Also, can you possibly supply an error message?
Alternatively, if you click the "launch binder" button from the README file on Github , you should get a working version running as a cloud version of RStudio, running within a web browser tab -- sometimes it can take a while for the container to load. (You may need to run 00_install_packages.Rmd first).
I look forward to hearing more.
How do you add a lasso tool to leaflet? The rectangular select that is being used? Is this a feature of leaflet or your own add on?
Hi Andrew. You are referring to the technique that happens at the 18 minute timestamp < th-cam.com/video/RGXUkXNrVxU/w-d-xo.html > ... That tool is part of leaflet. I did not take any steps to add it. My only caveat is to note that the video is two years old. Leaflet may have changed since then and maybe it's no longer a default action, but it was when I made the video. Does that help?
@@JohnLittle1 Thank you for responding John! I see that the leaflet js feature is used with the r package crosstalk here: rstudio.github.io/crosstalk/using.html However, I want to be able to do exactly what you are doing here where the datatable gets updated based on the selection on the map (in addition to my filters in the sidebarpanel). Do you have a link to the code that writes this flexdashboard example? I went to your git page but could not find the exact code.
@@casanova3131992 The code is here: github.com/libjohn/workshop_flexdashboards . Have a look at either 12_exercise_crosstalk_map_answers.Rmd or download and look at 12_exercise_crosstalk_map_answers.html. That exercise works progressively so start at the top, by the time you get to the section on Crosstalk you should see an example of how it all fits together.
In addition to the specifics I just posted, in looking closer, I must amend my original reply. Perhaps the brushing technique (that you call "lasso") is not part of leaflet, but part of crosstalk. Then it appears when combined with leaflet as configured together. I should know but I'm not a daily mapper and it's been a year or so since I have done that particular exercise. If you work your way through exercise 12 I think you'll find it all works. let me know if it doesn't. Good luck.
@@JohnLittle1 Thanks John. I'll keep working at it. I seem to keep having issues using crosstalk with the conditional filtering. I've shared my code on stack overflow if you are curious to see what I'm working with. I have sample code that I am working to include the crosstalk SharedData$new S6 class to update the datatable. stackoverflow.com/questions/65998983/r-shiny-leaflet-and-crosstalk-for-filtering
Very informative workshop and i learned a lot about Flexdashboard. Is there any instructions available for publishing flexdashboard to Netlify?
Hi @felix.
There are two resources I recommend...
- One is the Netlify document on simple single page deployment < www.netlify.com/blog/2016/10/27/a-step-by-step-guide-deploying-a-static-site-or-single-page-app/ >
- The other resource is the netlify chapter in Yihui Xie's book on blogdown < bookdown.org/yihui/blogdown/netlify.html >
FYI, this can be automated if you're using github, and then become very simple once you have netlify and github configured. People who are new or unfamiliar with HTML may find the netlify deployment process initially opaque -- but it's rather well documented. Netlify has a lot of documentation. Since Netlify is a freemium service the best way to deploy with them is read through the Netlify set-up document (referenced above).
package ‘summarywidget’ is not available (for R version 4.0.2) Is there an alternative we can substitute in or will this dashboard index.Rmd be updated please?
Hi @DM I'm not able to replicate the problem. Let's see if we can get to the bottom of this. I just booted a clean development machine with R version 4.0.2 (2020-06-22) and was able to build all the files in this workshop. So, couple questions....
Were you able to run 00_install_packages.Rmd? From there ,can you run 'devtools::install_github("kent37/summarywidget")' , i.e. line 8. If not, maybe try 'remotes::install_github("kent37/summarywidget")'. (grasping here. Honesty, I don't know that 'remotes', over 'devtools', will make any difference in this case.)
Despite build errors that you may see about 'summarywidget' are you able to knit the index.Rmd file?
Can you give more detail on your process, where the errors are occurring (line numbers, filenames, etc.), and the specific error messages?
just to be safe, give the whole thing a reboot; mabye there's a gremlin in the works.
@@JohnLittle1 I will have a go and feedback. Thank you.
Hi. I've been having trouble with the port from a static document to a dynamic one. Whenever I click on run app it just stays listening to a random Ip and doesn't do much
Hi @Emir. Are you using Shiny?
@@JohnLittle1 Hi. Thank you for you answer!
Yes! I've set the runtime to shiny in the YAML header.
Whenever I click run document it goes:
Loading required package: shiny
Listening on 127.0.0.1: XXXX
And it never gets past that
@@emirrojasaraya
I see. Well. I would say there should not be a space between the colon and the next value. The values following the colon should be numbers. (I realize you might be generalizing, but in practice the port number must be a number) 127.0.0.1:XXXX.
Since this workshop video is about flexdashboards and not specifically about Shiny, I'm not sure if I can be of much help. I recommend that you check the Shiny documentation on how to set the port. Secondarily, depending on the Operating System you are using and how that OS is configured, you may need OS admin permissions to enable that OS to allow listening on a particular port. **Sometimes**, you can skip the admin OS settings by using a very high port number (e.g. 888888).
But please know, I'm guessing about how to solve your problem. I cannot actually troubleshoot your shiny application. You may want to direct your question to the Shiny channel at RStudio Community: community.rstudio.com/c/shiny/8
Hope that helps.
@@JohnLittle1 Sure! Thanks for taking the time! Your video was very helpful on dashboards as well!
Please work on your microphone.