You could include the css part in tags$style
and put it within renderUI()
on the server side.
The easiest way would be put the rest of the css on the server side as well, but you could also read from the styles.css
file, see below.
Reproducible example:
library(shiny)
# Simulating a styles.css file
css_content <- "
h4 {
font-family: 'Lobster', cursive;
font-weight: 500;
line-height: 1.1;
color: #48ca3b;
}
"
writeLines(text = css_content, con = "styles.css")
css <- readLines(con = "styles.css") %>%
paste(collapse = "
")
ui <- fluidPage(
selectInput(inputId = 'selected_language', label = 'lang', choices = c('lao', 'english'), selected = 'english'),
uiOutput("css_style"),
h3("one"),
h4("two"),
h5("three")
)
server <- function(input, output, session) {
style <- reactive({
ifelse(
test = input$selected_language == "lao",
yes = "body { font-family: Phetsarath OT; }",
no = "body { font-family: Arial, Helvetica, sans-serif; }"
)
})
output$css_style <- renderUI({
tags$head(
tags$style(
HTML(
paste0(c(style(), css), collapse = "
")
)
)
)
})
}
shinyApp(ui, server)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…