我在 Flexdashboard 中有一个表,其列数可以更改。我可以动态计算列的对齐方式(默认对齐方式$23.45
作为字符向量,因此左对齐该值,尽管它是一个数字并且应该右对齐)。问题是我无法将此对齐传递回renderTable
作为一个值align
因为它是一个无功值。
我怎样才能将反应性对齐传递回renderTable
功能align
争论? (或者让我渲染一个具有反应性对齐的表格的替代方案)
MWE
---
title: "test"
output: flexdashboard::flex_dashboard
runtime: shiny
---
```{r}
library(flexdashboard)
library(shiny)
```
Inputs {.sidebar}
-------------------------------------
```{r}
selectInput(
"ncols",
label = "How many columns?",
choices = 1:5,
selected = 5
)
```
Column
-------------------------------------
### Test
```{r}
nc <- reactive({input$ncols})
aln <- reactive({substring('lllrr', 1, nc())})
renderTable({
x <- CO2[1:5, seq_len(nc()), drop = FALSE]
x[, 1] <- as.character(x[, 1])
x[3, 1] <- '<b>Mc1</b>'
x
}, align = aln(), sanitize.text.function = function(x) x)
```
结果是:
Warning: Error in .getReactiveEnvironment()$currentContext: Operation not
allowed without an active reactive context. (You tried to do something
that can only be done from inside a reactive expression or observer.)
尝试包裹aln()
in renderText(...)
i.e.
renderTable({
x <- CO2[1:5, seq_len(nc()), drop = FALSE]
x[, 1] <- as.character(x[, 1])
x[3, 1] <- '<b>Mc1</b>'
x
}, align = renderText(aln()),
sanitize.text.function = function(x) x)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)