I need to add a CSS class to a series of textOutput in a shiny app.
When I try, e.g.:
textOutput('text', class = 'error')
I get:
Warning: Error in textOutput: unused argument (class = "error")
It is possible to alter the CSS of the id of that textOutput. However, my ids are generated dynamically, so that is not a good solution. A possible alternative would be to 'grab' all ids that begin with/contain "error" (e.g. "error1", "error2"), but I am not sure if this is possible within my CSS style sheet.
You can add content to your Shiny app by placing it inside a *Panel function. For example, the apps above display a character string in each of their panels. The words “sidebar panel” appear in the sidebar panel, because we added the string to the sidebarPanel function, e.g. sidebarPanel("sidebar panel") .
A simple was to do this is using the shiny tagAppendAttributes
function. I normally find it easier to pipe the HTML output of shiny output objects into it like so:
library(shiny)
library(magrittr)
textOutput("foo") %>%
tagAppendAttributes(class = 'error')
Which produces the following output, which contains the error class.
<div class="shiny-text-output error" id="foo"></div>
You can also do the same thing with styles
textOutput("foo") %>%
tagAppendAttributes(style= 'color:green;')
<div id="foo" class="shiny-text-output" style="color:green;"></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With