CSS classes in shiny

I'm stuck with some CSS in a shiny app. Can someone point out where I have gone wrong here? I just want to change the styling of the class. I don't want to do it inline as there would be many links. I've spent an hour on this and can't get it to work, unless it is inline.

Edited to make the example a better representation of my problem.

library(shiny)
library(shinydashboard)

# link details
url <- "https://www.abc.net.au/news"
target <- "_blank"
text <- "test_only"
the_link <- tags$span(class = "sidelink",
                      p(tags$a(href = url, target = target, text))
)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    the_link # displays the link
  ),
  dashboardBody(
    tags$style(
      type = 'text/css',
      '.sidelink {text-decoration: underline; white-space: normal; margin-left: 10em; color: red; background-color: blue;}'
    )
  )
)

server <- function(input, output) { }

shinyApp(ui, server)

not sure if this is something you need: to use more specific CSS selector

library(shiny)
library(shinydashboard)

# link details
url <- "https://www.abc.net.au/news"
target <- "_blank"
text <- "test_only"
the_link <- tags$span(class = "sidelink",
                      p(tags$a(href = url, target = target, text))
)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    the_link # displays the link
  ),
  dashboardBody(
    tags$style(
      type = 'text/css',
      '.sidebar .sidelink p a {text-decoration: underline; white-space: normal; margin-left: 10em; color: red; background-color: blue;}'
    )
  )
)

server <- function(input, output) { }

shinyApp(ui, server)
1 Like

Yes, thanks heaps for that.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.