Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I simply add a css file to change the background color for my shiny app

Tags:

css

r

shiny

I'm re-asking my question from...

How do I find my shiny app's existing css?

...to generalize it for useRs that don't really get css yet. I've spent time reading over the rstudio css guide at http://shiny.rstudio.com/articles/css.html but it still doesn't click. I understand a couple things though that I think means I'm 90% there.

  1. the css file has to be linked in ui.r and from the theme argument in either the fluidPage or navbarPage function.
  2. Adding a very sparse css file to add a background color breaks the existing css.

So, my question is what is the simplest implementation of css to change the background color of the example histogram app at the shiny gallery at http://shiny.rstudio.com/gallery/faithful.html.

I think the answer to this question would help along some shiny app developers that are new to css like myself.

like image 224
cylondude Avatar asked Mar 31 '15 05:03

cylondude


1 Answers

Taken from Shiny article:

Once your Shiny app directory is set, you have two choices to link to your CSS file (your app won’t use the CSS until you do). You can:

  • set the theme argument of fluidPage to your document’s name
  • or include the file with the tags object.

But the simplest way really seems to use the function includeCSS():

includeCSS(path, ...)

Or just add an inline style in the example:

plotOutput(outputId = "main_plot", height = "300px" style="background-color:pink;"),
like image 68
Persijn Avatar answered Sep 18 '22 12:09

Persijn