我有一个闪亮的 R 应用程序,其中使用“renderTable”函数来渲染动态创建的表。该表在一种情况下可以具有 3 个字符列和 4 个数字列,在另一种情况下可以具有 2 个字符列和 2 个数字列。ui.R 的 renderTable 代码是:
output$table1 <- renderTable({
d1<-data()
print(format(d1, big.mark=",", scientific=FALSE,justify="right", nsmall=0))
})
Run Code Online (Sandbox Code Playgroud)
这适用于除 justify 之外指定的所有格式选项。所有数字列在输出中均左对齐。
谁能解释一下为什么?
在 flexdashboard 包中,图表标题(网格中单元格的标题)通过 3 个哈希标记(例如,### Chart title here)。我想将一个反应值传递给这个标头。通常人们可以定义一个 UI 并推送它(/sf/answers/3368280821/),但井号告诉编织这是一个图表标题。我还考虑过使用`r CODE HERE`内嵌代码(例如,)传递反应值,如下面的 MWE 所示。您可以将内联文本用于图表标题,但当它包含反应值时则不能。这导致错误:
Error in as.vector: cannot coerce type 'closure' to vector of type 'character'
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我如何将月份作为 chart.title 传入?
---
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)', …Run Code Online (Sandbox Code Playgroud)