在flexdashboard中添加动态标题,或者在gauge()中添加动态标题
Adding dynamic titles in flexdashboard, or adding dynamic titles to gauge()
我正在 flexdashboard 中创建一个仪表页面。我希望能够从单独的 csv 更新仪表的标题和值,以便我团队的其他成员可以更新值而无需触摸代码。
我怎样才能:
- 使标题动态化,以便它们取自 csv 中的文本?例如:
### myData$myTitles[1]
(除了,当然,这行不通。)
- 或 为仪表添加标题(这样我就可以将框标题留空)。
下面是一些示例代码。如果有任何建议,我将不胜感激。
---
title: "My dynamic gauges"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
library(readxl)
library(dplyr)
#myData <- read_csv("mydata.csv")
myData <- tibble(myTitles = c("title 1", "title 2", "title 3","title 4","title 5","title 6"),
myValues = c(2,4,3,3,5,2))
```
Column
-----------------------------------------------------------------------
<h3> Column Name 1 </h3>
### title 1
```{r}
gauge(myData$myValues[1],
min = 0,
max = 6,
gaugeSectors(success = c(0,2),
warning = c(3,4),
danger = c(5,6)))
```
### title 2
```{r}
gauge(myData$myValues[2],
min = 0,
max = 6,
gaugeSectors(success = c(0,2),
warning = c(3,4),
danger = c(5,6)))
```
Column
-----------------------------------------------------------------------
<h3> Column Name 2 </h3>
### title 3
```{r}
gauge(myData$myValues[3],
min = 0,
max = 6,
gaugeSectors(success = c(0,2),
warning = c(3,4),
danger = c(5,6)))
```
### title 4
```{r}
gauge(myData$myValues[4],
min = 0,
max = 6,
gaugeSectors(success = c(0,2),
warning = c(3,4),
danger = c(5,6)))
```
Column
-----------------------------------------------------------------------
<h3> Column Name 3 </h3>
### title 5
```{r}
gauge(myData$myValues[5],
min = 0,
max = 6,
gaugeSectors(success = c(0,2),
warning = c(3,4),
danger = c(5,6)))
```
### title 6
```{r}
gauge(myData$myValues[6],
min = 0,
max = 6,
gaugeSectors(success = c(0,2),
warning = c(3,4),
danger = c(5,6)))
```
这里有一个简单的解决方案:
```{r results='asis'}
cat(paste0("### ",myData$myTitles[1]))
```
你应该使用它而不是 ### myData$myTitles[1]
我正在 flexdashboard 中创建一个仪表页面。我希望能够从单独的 csv 更新仪表的标题和值,以便我团队的其他成员可以更新值而无需触摸代码。
我怎样才能:
- 使标题动态化,以便它们取自 csv 中的文本?例如:
### myData$myTitles[1]
(除了,当然,这行不通。)
- 或 为仪表添加标题(这样我就可以将框标题留空)。
下面是一些示例代码。如果有任何建议,我将不胜感激。
---
title: "My dynamic gauges"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
library(readxl)
library(dplyr)
#myData <- read_csv("mydata.csv")
myData <- tibble(myTitles = c("title 1", "title 2", "title 3","title 4","title 5","title 6"),
myValues = c(2,4,3,3,5,2))
```
Column
-----------------------------------------------------------------------
<h3> Column Name 1 </h3>
### title 1
```{r}
gauge(myData$myValues[1],
min = 0,
max = 6,
gaugeSectors(success = c(0,2),
warning = c(3,4),
danger = c(5,6)))
```
### title 2
```{r}
gauge(myData$myValues[2],
min = 0,
max = 6,
gaugeSectors(success = c(0,2),
warning = c(3,4),
danger = c(5,6)))
```
Column
-----------------------------------------------------------------------
<h3> Column Name 2 </h3>
### title 3
```{r}
gauge(myData$myValues[3],
min = 0,
max = 6,
gaugeSectors(success = c(0,2),
warning = c(3,4),
danger = c(5,6)))
```
### title 4
```{r}
gauge(myData$myValues[4],
min = 0,
max = 6,
gaugeSectors(success = c(0,2),
warning = c(3,4),
danger = c(5,6)))
```
Column
-----------------------------------------------------------------------
<h3> Column Name 3 </h3>
### title 5
```{r}
gauge(myData$myValues[5],
min = 0,
max = 6,
gaugeSectors(success = c(0,2),
warning = c(3,4),
danger = c(5,6)))
```
### title 6
```{r}
gauge(myData$myValues[6],
min = 0,
max = 6,
gaugeSectors(success = c(0,2),
warning = c(3,4),
danger = c(5,6)))
```
这里有一个简单的解决方案:
```{r results='asis'}
cat(paste0("### ",myData$myTitles[1]))
```
你应该使用它而不是 ### myData$myTitles[1]