Question

I'm making my first shiny application and am having trouble linking an external css file. I've seen a few references where people have explained how to do it and even showed example code, but I haven't had any luck. Most of the example I've seen it working used the bootstrapPage, like this:

  shinyUI(bootstrapPage(
    tags$head(
      tags$title('Example linked stylesheet'),
      tags$link(rel = 'stylesheet', type = 'text/css', href = 'assets/ace-shiny.css'),
    ))

I'm using fluidPage, and don't know if that's my problem. My attempt is below. I've confirmed that my working directory is where I think it is, and contains the "Assets" folder which holds the css file. I know the tags$head bit is working, since if I uncomment the tags$style there, it gets applied.

shinyUI(fluidPage(
  tags$head(
     tags$link(rel="stylesheet", type="text/css", href="assets/styles.css")
     #tags$style(type='text/css', "body {background-color: black;}")
  ))

My CSS at this stage is simple (below), so I know it's not the problem.

body {background-color: red;}

Am I missing something obvious? Thanks for reading. Mike

Was it helpful?

Solution

You need to put your .css file in a subdirectroy called www

NOTE

As gruvn mentioned in the comments, you need to make your href just refer to the files, and not include the www path. That is, use href='mycss.css' and not href='www/mycss.css'

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top