Bắt đầu ngayBắt đầu miễn phí

Di chuyển Input vào hộp biểu đồ

Hãy di chuyển phần nhập của người dùng vào ngay trong biểu đồ mà nó tác động.

Bài tập này là một phần của khóa học

Xây dựng Dashboard với flexdashboard

Xem khóa học

Hướng dẫn bài tập

  • Di chuyển thanh trượt từ thanh bên vào biểu đồ Trip Durations, đặt phía trên đồ thị.
  • Xóa thanh bên khỏi dashboard.
  • Lưu ý cách bố cục giữa thanh trượt nhập liệu và đồ thị trong biểu đồ, và cách chúng lấp đầy (hoặc không lấp đầy) hộp một cách phù hợp.

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

{"my_document.Rmd":"---\ntitle: \"Bike Shares Daily\"\noutput: \n  flexdashboard::flex_dashboard:\n    orientation: columns\n    vertical_layout: fill\nruntime: shiny\n---\n\n```{r global, include=FALSE}\nlibrary(flexdashboard)\nlibrary(readr)\nlibrary(leaflet)\nlibrary(DT)\nlibrary(tidyverse)\nlibrary(lubridate)\nlibrary(plotly)\n\ntrips_df <- read_csv('https://assets.datacamp.com/production/repositories/1448/datasets/1f12031000b09ad096880bceb61f6ca2fd95e2eb/sanfran_bikeshare_joined_oneday.csv') %>%\n  mutate(duration_min = duration_sec / 60) %>%\n  filter(duration_min <= 8 * 60) # filtering out trips over 8 hours as suspicious\n\n```\n\nColumn {data-width=200 .sidebar}\n-----------------------------------------------------------------------\n\n```{r}\nsliderInput(\"duration_bin\", label = \"Select # of minutes to bin trip durations:\",\nmin = 1, max = 15, value = 5, step = 1)\n```\n\nColumn {data-width=450}\n-----------------------------------------------------------------------\n\n### Origins\n\n```{r}\n\nrenderLeaflet({\n  trips_df %>%\n    rename(latitude = start_latitude,\n           longitude = start_longitude) %>%\n    group_by(start_station_id, latitude, longitude) %>%\n    count() %>%\n    leaflet() %>%\n    addTiles() %>%\n    addCircles(radius = ~n)\n})\n\n```\n\nColumn {data-width=350}\n-----------------------------------------------------------------------\n\n### Total Trips\n\n```{r}\n\nrenderValueBox({\n  valueBox(prettyNum(trips_df %>%\n                       nrow(), big.mark = ','), \n           icon = 'fa-bicycle')\n})\n\n```\n\n### Trip Durations\n\n```{r}\n\nrenderPlot({trips_df %>%\n  mutate(`Trip Duration (min)` = duration_sec / 60) %>%\n  ggplot(aes(x = `Trip Duration (min)`)) +\n  theme_bw() +\n  geom_histogram(binwidth = input$duration_bin) +\n  ylab('# Trips')\n})\n\n\n```\n\n\n"}
Chỉnh sửa và Chạy Mã