I'm assuming that in a reusable module the user can freely choose the namespace (i.e. can pass anything as an id
), so it is impossible to hard code e.g. the CSS. I know how to refer to the id
in case of inline CSS or internal stylesheet, like in the example below:
library(shiny)
library(glue)
modUI <- function(id) {
ns <- NS(id)
tagList(
tags$head(tags$style(glue("#{id}-color {{background-color: green;}}"))),
actionButton(ns("color"), "I'm green")
)
}
modServer <- function(id) {
moduleServer(
id,
function(input, output, session) {
}
)
}
ui <- fluidPage(
modUI("example")
)
server <- function(input, output, session) {
modServer("example")
}
shinyApp(ui, server)
But let's say that using iternal stylesheet or inline CSS is rather not the best practice to style the whole module and I don't know how to do something similar in the separate .css
file.
What would be the best in this case? Perhaps something different than CSS?