本文于2026-03-28更新。 如发现问题或者有建议,欢迎提交 Issue
部分展示可以参考 博客监控 。 主要参考 @RStudioflexdashboard 。
包的受欢迎程度
## Error in `library()`:
## ! there is no package called 'tidyverse'
## Error in `library()`:
## ! there is no package called 'packagefinder'
## Error in `library()`:
## ! there is no package called 'dlstats'
## Error in `library()`:
## ! there is no package called 'cranly'
## Error in `library()`:
## ! there is no package called 'lubridate'
sem_pkg <-
bind_rows(
'dashboard' %>%
findPackage() %>%
as_tibble()
)
sem_pkg_download <-
sem_pkg %>%
rename_all(tolower) %>%
arrange(desc(score)) %>%
distinct(name) %>%
# head(100) %>%
.$name %>%
# 可以插入 vector,所以不需要map
cran_stats()
sem_pkg_mostdownload <-
sem_pkg_download %>%
group_by(package) %>%
summarize(downloads = mean(downloads)) %>%
arrange(desc(downloads))
sem_pkg_download %>%
filter(year(end) >= 2017) %>%
filter(package %in% sem_pkg_mostdownload[1:10,]$package) %>%
mutate(is_high = package %in% sem_pkg_mostdownload[1:5,]$package) %>%
ggplot(aes(x=end,y=downloads,col=package)) +
geom_line() +
facet_wrap(~is_high,scales = 'free_y')- 目前
flexdashboard包还处于上升期。
元素定义
每个元素定义,通过一个#来展示。
columns
Column {data-width=750}
-----------------------------------------------------------------------
data-width=750和data-width=250把一个页面按照1:3分开。
[@McVey2018 * [Column widths |
R](https://campus.datacamp.com/courses/building-dashboards-with-flexdashboard/dashboard-layouts?ex=7)
]
rows
output:
flexdashboard::flex_dashboard:
orientation: rows
修改yaml参数 * [@McVey2018 [Row orientation | R](https://campus.datacamp.com/courses/building-dashboards-with-flexdashboard/dashboard-layouts?ex=8) ]
tabsets
Column {.tabset data-width=650}
-----------------------------------------------------------------------
写在开头即可。 参考 RStudio
不是对
Overview
=====================================
pages

Overview
=====================================
Add the text “Overview” followed by a line with 16 or more = to add the first page. [@McVey2018 * [Pages | R](https://campus.datacamp.com/courses/building-dashboards-with-flexdashboard/dashboard-layouts?ex=11) ]
Web-friendly plot
参考 ggplot2使用技巧 Web-friendly plot
leaflet map
leaflet包可以构建地图,只要给予经纬度 [@McVey2018 * [Add a leaflet map |
R](https://campus.datacamp.com/courses/building-dashboards-with-flexdashboard/data-visualization-for-dashboards?ex=9)
* [Color indicators |
R](https://campus.datacamp.com/courses/building-dashboards-with-flexdashboard/dashboard-components?ex=4)
]
vertical_layout: fill的yaml参数可以让地图覆盖整个页面。
## Error in `library()`:
## ! there is no package called 'flexdashboard'
## Error in `library()`:
## ! there is no package called 'readr'
## Error in `library()`:
## ! there is no package called 'tidyverse'
## Error in `library()`:
## ! there is no package called 'leaflet'
stations_df <- read_csv('http://s3.amazonaws.com/assets.datacamp.com/production/course_6355/datasets/stations_data.csv')## Error in `read_csv()`:
## ! could not find function "read_csv"
## Error in `leaflet() %>% addTiles() %>% addMarkers(lat = stations_df$latitude, lng = stations_df$
## longitude)`:
## ! could not find function "%>%"
data = stations_df参数也可以直接给data.frame
[@McVey2018 * [Add a leaflet map directly from
dataframe |
R](https://campus.datacamp.com/courses/building-dashboards-with-flexdashboard/data-visualization-for-dashboards?ex=10)
]
Assuming "longitude" and "latitude" are longitude and latitude, respectively自动识别了经纬度的变量。
## Error in `leaflet(stations_df) %>% addTiles() %>% addMarkers()`:
## ! could not find function "%>%"
value box
date_data %>%
filter(date > now() - ddays(90)) %>%
count %>%
pull %>%
valueBox(., caption = "近90天发文量", icon="fa-pencil"
, color = ifelse(. < 30, "warning", "primary"))
caption显示的文字color显示的颜色icon显示的背景图案,更多参考 https://ionicons.com/
add link
valueBox(median_min,
caption = 'Median Trip Duration (Minutes)',
icon = 'fa-clock-o',
href = '#trip-duration'
)
href参数可以接短链接或者长链接 [@McVey2018 * [Linking |
R](https://campus.datacamp.com/courses/building-dashboards-with-flexdashboard/dashboard-components?ex=5)
]
- 如果标题是
trip duration如果是英文可以直接用#trip-duration引用。 - 如果标题用
#sometag进行了标记,那么就可以用#sometag引用。
gauge
gauge函数展示指标 [@McVey2018 *
[Create gauge |
R](https://campus.datacamp.com/courses/building-dashboards-with-flexdashboard/dashboard-components?ex=3)
]
gauge(value = 60,
min = 0,
max = 100)
Color indicators
gauge(value = pct_short_trips,
min = 0,
max = 100,
sectors = gaugeSectors(success = c(67, 100),
warning = c(33, 66),
danger = c(0, 32)))
table
- 使用
kable函数做静态表格,可以使用滚轮上下滑动 - 使用
DT::datatable函数做动态表格 [@McVey2018
extensions to download
mtcars %>%
DT::datatable(
rownames = FALSE,
extensions = 'Buttons', options = list(
dom = 'Bfrtip',
buttons = c('copy', 'csv', 'excel', 'pdf', 'print')
)
)## Error in `mtcars %>% DT::datatable(rownames = FALSE, extensions = "Buttons", options = list(
## dom = "Bfrtip", buttons = c("copy", "csv", "excel", "pdf", "print")))`:
## ! could not find function "%>%"
extensions = 'Buttons'可以选择下载的方式,更多见 https://datatables.net/extensions/index [@McVey2018
Caption
比如可以加上数据来源等,如 > ... [@McVey2018 * [Captions |
R](https://campus.datacamp.com/courses/building-dashboards-with-flexdashboard/dashboard-components?ex=11)
]
Storyboards
yaml中声明storyboard: true,然后每个标题### some text就是
Storyboard 了。 [@McVey2018 * [Storyboards |
R](https://campus.datacamp.com/courses/building-dashboards-with-flexdashboard/dashboard-components?ex=13)
]
Commentary
在R
Chunk后插入***,然后写入1.或者+即可。
[@McVey2018 * [Storyboard Commentary |
R](https://campus.datacamp.com/courses/building-dashboards-with-flexdashboard/dashboard-components?ex=14)
]
