【发布时间】:2018-06-17 19:54:00
【问题描述】:
在 flexdashboard 包中,图表标题(网格中单元格的标题)由 3 个哈希标记(例如,### Chart title here)组成。我想将反应值传递给此标头。通常可以定义一个 UI 并推送它(https://stackoverflow.com/a/48118297/1000343),但哈希标记告诉编织者这是一个图表标题。我还考虑过使用内联代码(例如,`r CODE HERE`)传递反应值,如下面的 MWE 所示。您可以将内联文本用于图表标题,但不能在它包含反应值时使用。这会导致错误:
Error in as.vector: cannot coerce type 'closure' to vector of type 'character'
在这种情况下,我如何将月份作为 chart.title 传递?
MWE(删除最后一行允许运行)
---
title: "test"
output: flexdashboard::flex_dashboard
runtime: shiny
---
```{r}
library(flexdashboard)
library(shiny)
```
Inputs {.sidebar}
-------------------------------------
```{r}
selectInput(
"month",
label = "Pick a Month",
choices = month.abb,
selected = month.abb[2]
)
getmonth <- reactive({
input$month
})
renderText({getmonth()})
```
Column
-------------------------------------
### `r sprintf('Box 1 (%s)', month.abb[1])`
### `r sprintf('Box 2 (%s)', renderText({getmonth()}))`
【问题讨论】:
-
我认为如果不破坏原始 HTML 中的图表标题,这将很难。我有 something 可以工作,但它真的很丑。
标签: r shiny flexdashboard