Having a homework for shiny that builds through multiple steps is…kinda nuts. What I’d like you to do is save an R file for each one (prepend 1_, 2_, 3_, etc. so we know which number it is) and then zip it all up to submit. For when you post the app, give us a URL!
There are a LOT of extra credit options here. You don’t have to do them in order, or do them all. But, take a gander. This is all to help you prep for your final project!
We’ve been using the coronavirus
package to this point, but, while it rejiggers itself for automated data updates, let’s tap it from the source!
library(readr)
coronavirus <- read_csv("https://github.com/RamiKrispin/coronavirus-csv/raw/master/coronavirus_dataset.csv",
col_types = "ccddDdc")
Province.State | Country.Region | Lat | Long | date | cases | type |
---|---|---|---|---|---|---|
Zhejiang | China | 29.1832 | 120.0934 | 2020-05-09 | 0 | recovered |
Zhejiang | China | 29.1832 | 120.0934 | 2020-05-10 | 0 | recovered |
Zhejiang | China | 29.1832 | 120.0934 | 2020-05-11 | 0 | recovered |
Zhejiang | China | 29.1832 | 120.0934 | 2020-05-12 | 0 | recovered |
Zhejiang | China | 29.1832 | 120.0934 | 2020-05-13 | 0 | recovered |
Zhejiang | China | 29.1832 | 120.0934 | 2020-05-14 | 0 | recovered |
Today, we’ll build a shiny app that works with this data.
You know how to do this. Use Rstudio or hand-code your own template. Save it as 1_app.R
. Have it load the data above (straight from the source!) Make sure that it runs.
Choose a layout. It can be a sidebar layout, as we’ve been doing, or, try setting up something different from here. Save this as 2_app.R
after making sure your app runs!
There are a LOT of themes for shiny. The ones that come pre-installed are here along with a tutorial. Make your app stylin! Make sure your app runs.
Scour the web for shiny packages (seriously, just google shiny packages or other terms) to use your own unique layout and theme that is not pre-packaged. 2 poitns for theme, 2 points for layout. I’m not saying how many points we’ll give for shiny lcars….
OK, you are all setup. Using tableOutput()
in the proper place in your UI and renderTable()
in your server, show us the tail of the coronavirus table. Make sure your app runs.
OK, now have it create a ggplot that, using plotOutput()
and renderPlot()
shows us the worldwide trend in confirmed cases of coronavirus. Note - you’ll have to do some data manipulation here! But you’ve done this before. Have the title tell us what date this is current to. Make sure your app runs. Note - check yourself against a dashboard like this to make sure your results are more or less correct.
Now, add two inputs. One allows users to chose a country. The second allows them to select the type of cases to display (confirmed, death, recovered). Use whatever *Input
functions you would like. Now, where you have OUTPUTS for global trends and a tail of a data table, replace them with outputs that show the trend for the selected country and type and the table for the selected country and type. Make sure your app runs.
Using http://shiny.umb.edu, upload your code, make sure the app works (in case you have to install any libraries), and then tell us the link! If you’ve forgotten how, go back and watch the last 10-15 minutes of our Shiny Lab!
Use tabsets so that all of the outputs are not returned all at once. Deploy this!
Using tmap
, leafletOutput()
, and renderLeaflet()
(don’t worry, shiny takes care of making it interactive) add a worldmap somewhere (your choice how to do this layout - will be easier with the tabs!) that shows the final # of whatever type you have selected across a worldmap (hey, you know how to merge this data with a worldmap - maybe you have some code for it, that, for additional extra credit, you can source in!)
Set up the app so that, when you select a country, have it zoom in on the country (replot but center on that country).
Can you use information at smaller spatial scales than countries? You might have to use another spatial data source - at least a different function within rnaturalearth
or from somewhere else. Either have this smaller-scale information represented on the global map OR when you select a country, plot JUST that country with smaller province/state areas as the internal borders. Good luck!
Go wild. Do something different with this! Use other output types, use other input types, filter differently, map differently - Have fun! And tell us what you did. Deploy it. We can’t wait to see!