ANam
ANam

Reputation: 347

How to apply CSS styling to modularized shiny code?

I am try to stylize my UI in a shiny app that I am making. I had previously built a fairly comprehensive map that I now have to modularize to improve readability. Unfortunately, I cannot seem to understand how to go about applying CSS styles while using modules.

The part where I try and apply the styling is in the UI function at the bottom:

div(class="outer",

        tags$head(includeCSS("styles.css")),

          baseMapUI("bottommap")
        )

I'm unsure if I'm saving the CSS file in the wrong location. I do set the working directory at the start to my /Data folder so I have saved it there as well. Since no error is being returned (i.e, file not found), I believe the issue lies somewhere else.

My final result would have a stylized absolutePanel but in reality the CSS styles are not being applied at all. For reference, this is my CSS file:

input[type="number"] {
  max-width: 80%;
}

div.outer {
  position: fixed;
  top: 41px;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  padding: 0;
}

/* Customize fonts */
body, label, input, button, select { 
  font-family: 'Helvetica Neue', Helvetica;
  font-weight: 200;
}
h1, h2, h3, h4 { font-weight: 400; }

#controls {
  /* Appearance */
  background-color: white;
  padding: 0 20px 20px 20px;
  cursor: move;
  /* Fade out while not hovering */
  opacity: 0.65;
  zoom: 0.9;
  transition: opacity 500ms 1s;
}
#controls:hover {
  /* Fade in while hovering */
  opacity: 0.95;
  transition-delay: 0;
}

/* Position and style citation */
#cite {
  position: absolute;
  bottom: 10px;
  left: 10px;
  font-size: 12px;
}

/* If not using map tiles, show a white background */
.leaflet-container {
  background-color: white !important;
}

Upvotes: 2

Views: 1344

Answers (1)

Stéphane Laurent
Stéphane Laurent

Reputation: 84519

id = ns("controls") generates the id bottommap-controls. So the selector must be #bottommap-controls instead of #controls.

Upvotes: 1

Related Questions