class: center, middle, inverse, title-slide .title[ # Advanced RMarkdown Course ] .subtitle[ ##
Module 2 ] .author[ ### ] .date[ ###
contact@appliedepi.org
] --- <style type="text/css"> .remark-slide table{ border: none } .remark-slide-table { } tr:first-child { border-top: none; } tr:last-child { border-bottom: none; } .center2 { margin: 0; position: absolute; top: 50%; left: 50%; } </style> <style type="text/css"> /* THIS IS A CSS CHUNK - THIS IS A COMMENT */ /* Size of font in code echo. E.g. 10px or 50% */ .remark-code { font-size: 70%; } /* Size of font in text */ .medium-text { font-size: 75%; } /* Size of font in tables */ .small-table table { font-size: 6px; } .medium-table table { font-size: 8px; } .medium-large-table table { font-size: 10px; } </style> # Thank you for joining us Brief introductions from the instructors **Thank you for your service** *to your community in these busy times for public health. We are glad that you are taking the time to learn R with us.* ??? Do a brief round of introductions --- # Looping Reports - We can take one report RMarkdown file to create multiple reports. <img src="../../images/rmd2/loop.png" width="55%" /> - In an external R-script, we can pass a list of districts, for which we want to create separate reports, to the RMarkdown report script in a loop. - This will create a report HTML, PDF, or DOCX for each district. --- # Looping Reports We use the `render()` function from the `rmarkdown` package. The 3 arguments needed are: - `input`: RMarkdown **Rmd** file to be run for each region - `output_file`: Naming convention for each output HTML file - `params`: Parameter that specifies which region we are running the Rmd for ```r rmarkdown::render(input = here("exercises","scripts","Ebola_Report.Rmd"), output_file = str_glue("Report_{r}_{Sys.Date()}.html"), params = list(region = r) ) ``` --- # Dynamic Sections - On the other hand, if we want all of these plots in the same document, we can loop through a list of districts within the RMarkdown file and print a section for each district. <img src="../../images/rmd2/dynamic_sections.png" width="50%" /> - Even if the number of districts changes within the data, RMarkdown can create sections (and plots) for each of them without the need to specify the districts in the code. --- # Dynamic Tabs - If we want all of these plots in the same document but under different tabs, we can loop through a list of districts within the RMarkdown file and print a tab for each district. <img src="../../images/rmd2/dynamic_tabs.png" width="75%" /> - Again, RMarkdown can create tabs (and plots) for each of them accurately without specifying the districts in the code. --- # Dynamic Tabs - We will be able to click on the tab we want (here District 2 is selected) and see the corresponding plots, visualizations, and/or summaries. <img src="../../images/rmd2/dynamic_tabs2.png" width="75%" /> --- # Dynamic Tabs - District 3 selected: <img src="../../images/rmd2/dynamic_tabs3.png" width="75%" /> --- # Dynamic Tabs - District 4 selected: <img src="../../images/rmd2/dynamic_tabs4.png" width="75%" /> --- # Dynamic Tabs - District 5 selected: <img src="../../images/rmd2/dynamic_tabs5.png" width="75%" /> --- # Demo *Looping reports* *Dynamic tabs* *Dynamic sections* --- # FlexDashboard * `flexdashboard` makes it easy to create interactive dashboards for R, using R Markdown. * Because you've already learned to work within the RMarkdown environment, you'll be able to create dashboards, similar to what we've been creating, with some additional tools. * We'll create tabs with figures, but they'll be editable within your browser. Learn more here: https://pkgs.rstudio.com/flexdashboard/ --- # FlexDashboard Here's the first tab we'll make, with data that is searchable and the same epidemic curve: <img src="../../images/rmd2/flexdashboard_main.png" width="100%" /> --- # FlexDashboard - `htmlwidgets` Next, we'll be adding `htmlwidgets` to the subsequent tabs. `htmlwidgets` provides us with additional tools to make dynamic figures. Just a line or two of R code can be used to create interactive visualizations. Learn more here: https://www.htmlwidgets.org/ --- # FlexDashboard - `leaflet` The `leaflet` package allows us to create dynamic and interactive maps. We can change the view, and we can also zoom in! You'll see the static map (which we'll also learn to make) on the left. The `leaflet` map is on the right: <img src="../../images/rmd2/flexdashboard_maps.png" width="100%" /> --- # FlexDashboard - `visNetwork` At the beginning of an epidemic, it might be useful to visualize transmission events, especially if infector-infectee pairs are known. We'll make a `visNetwork` visualization from the beginning of the Ebola outbreak, shown below on the left. <img src="../../images/rmd2/flexdashboard_epi.png" width="100%" /> --- # FlexDashboard - `plotly` We can use the `plotly` package very easily with the `ggplot2` package to make plots dynamic. `plotly` plots can be changed by legend and by axis, in can you're interested in focusing on one subgroup or one particular time in the epidemic curve. --- # FlexDashboard - `plotly` The `plotly` plot is shown on the left here, but you'll see what is dynamic about this plot during the demo: <img src="../../images/rmd2/flexdashboard_epi.png" width="100%" /> --- # FlexDashboard - `dygraphs` `dygraphs` is similar to `plotly`, though it requires a different syntax than `ggplot` does. Here, we'll use `dygraphs` to plot the case curve along with the death curve: <img src="../../images/rmd2/flexdashboard_deaths.png" width="100%" /> --- # Demo **flexdashboard** **htmlwidgets** *leaflet*, *plotly*, *visNetwork*, and *dygraphs*