Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add CSS class to shiny textOutput

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.

like image 402
sebdalgarno Avatar asked Aug 16 '18 01:08

sebdalgarno


People also ask

How do you add text to the shiny app?

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") .


Video Answer


1 Answers

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>
like image 159
aeongrail Avatar answered Sep 24 '22 12:09

aeongrail