我需要在 Shiny 的应用程序中向一系列 textOutput 添加一个 CSS 类。
当我尝试时,例如:
textOutput('text', class = 'error')
我得到:
Warning: Error in textOutput: unused argument (class = "error")
可以更改该 textOutput 的 id 的 CSS。但是,我的 id 是动态生成的,所以这不是一个好的解决方案。一种可能的替代方法是“抓取”以/包含“error”(例如“error1”、“error2”)开头的所有 id,但我不确定这在我的 CSS 样式表中是否可行。
最佳答案
一个简单的方法是使用 Shiny 的 tagAppendAttributes
函数。我通常发现将 Shiny 输出对象的 HTML 输出通过管道传输到其中更容易,如下所示:
library(shiny)
library(magrittr)
textOutput("foo") %>%
tagAppendAttributes(class = 'error')
这会产生以下输出,其中包含错误类。
<div class="shiny-text-output error" id="foo"></div>
你也可以用样式做同样的事情
textOutput("foo") %>%
tagAppendAttributes(style= 'color:green;')
<div id="foo" class="shiny-text-output" style="color:green;"></div>
关于css - 将 CSS 类添加到 Shiny 的 textOutput,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51868365/