gpt4 book ai didi

渲染函数的 react 参数

转载 作者:行者123 更新时间:2023-12-04 13:41:09 24 4
gpt4 key购买 nike

我在 flexdashboard 中有一个表格,它的列数可以改变。我可以即时计算列的对齐方式(默认对齐方式将 $23.45 视为字符向量,因此左对齐值,尽管它是一个数字并且应该右对齐)。问题是我无法将此对齐作为 renderTable 的值传递回 align,因为它是一个 react 值。

如何将 react 性对齐传递回 renderTable 函数的 align 参数? (或者让我用响应式(Reactive)对齐呈现表格的替代方法)

移动电源

---
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() 包装在 renderText(...) 中,即

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)

关于渲染函数的 react 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48116762/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com