根据输入更改CSS属性
在我的应用程序中,CSS属性位于单独的文件中,并通过根据输入更改CSS属性,css,r,shiny,Css,R,Shiny,在我的应用程序中,CSS属性位于单独的文件中,并通过includeCSS('./www/styles.CSS')包含在ui中 是否可以根据输入值动态更改字体族属性 e、 g.用户界面包括: selectInput(inputId = 'selected_language', label = 'Choose language', choices = c('lao', 'english'), selected = 'english') 当选择“lao”时,使用body{font-family:Ph
includeCSS('./www/styles.CSS')
包含在ui中
是否可以根据输入值动态更改字体族属性
e、 g.用户界面包括:
selectInput(inputId = 'selected_language', label = 'Choose language', choices = c('lao', 'english'), selected = 'english')
当选择“lao”时,使用
body{font-family:Phetsarath OT;}
,而如果选择“english”,则使用body{font-family:Arial,Helvetica,sans serif;}
。您可以将css部分包含在标记$style
中,并将其放入服务器端的renderUI()
中
最简单的方法是将css的其余部分也放在服务器端,但您也可以从styles.css
文件中读取,请参见下文
可复制示例:
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 = "\n")
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 = "\n")
)
)
)
})
}
shinyApp(ui, server)
库(闪亮)
#模拟styles.css文件
css\u content您可以在标记$style
中包含css部分,并将其放在服务器端的renderUI()
中
最简单的方法是将css的其余部分也放在服务器端,但您也可以从styles.css
文件中读取,请参见下文
可复制示例:
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 = "\n")
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 = "\n")
)
)
)
})
}
shinyApp(ui, server)
库(闪亮)
#模拟styles.css文件
css_内容新发布的Shinny 1.6.0允许动态主题化新发布的Shinny 1.6.0允许动态主题化