CommencerCommencer gratuitement

Static table

Let's imagine that your dashboard viewers need to see how many trips started and ended at each bikeshare station to manage balancing of bikes. We can provide this information in a simple table.

Cet exercice fait partie du cours

Building Dashboards with flexdashboard

Afficher le cours

Instructions

  • Add a table in the Station Usage chart that contains the data in station_trips_df, using the kable() function.
  • Knit and expand the HTML viewer to explore the resulting table. Try scrolling down.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

{"my_document.Rmd":"---\ntitle: \"Bike Shares Daily\"\noutput: \n  flexdashboard::flex_dashboard:\n    orientation: columns\n    vertical_layout: fill\n---\n\n```{r setup, include=FALSE}\nlibrary(flexdashboard)\nlibrary(readr)\nlibrary(tidyverse)\nlibrary(lubridate)\nlibrary(plotly)\nlibrary(knitr)\nlibrary(DT)\n\ntrips_df <- read_csv('https://assets.datacamp.com/production/course_6355/datasets/sanfran_bikeshare_joined_oneday.csv')\n```\n\nColumn {data-width=650}\n-----------------------------------------------------------------------\n\n### Station Usage\n\n```{r}\n\nstation_trips_df <- trips_df %>%\n  select(start_station_name, end_station_name) %>%\n  pivot_longer(cols = start_station_name:end_station_name, names_to = 'Type', values_to = 'Station') %>%\n  group_by(Station, Type) %>%\n  summarize(n_trips = n()) %>% \n  mutate(Type = ifelse(Type == 'start_station_name', 'Trip Starts', 'Trip Ends')) %>%\n  pivot_wider(names_from = 'Type', values_from = 'n_trips') %>%\n  replace_na(list(`Trip Starts` = 0, `Trip Ends` = 0)) %>%\n  mutate(Gap = `Trip Ends` - `Trip Starts`)\n\n```\n\n\nColumn {data-width=350}\n-----------------------------------------------------------------------\n\n### Median Trip Length\n\n\n### % Short Trips\n\n\n### Trips by Start Time\n\n\n"}
Modifier et exécuter le code