在整个R Shiny应用程序中更改字体系列:CSS / HTML



是否可以更改整个闪亮仪表板应用程序的默认字体?包括侧边栏、正文、标题、应用程序中的 ggplot 等的字体?

我知道您可以在每件作品中添加字体系列语句 (例如:h2(strong(textOutput("t"((,style = "font-family: 'Arial';"((, 但我希望我的整个应用程序都使用 Arial,我不想为每个功能编写一行代码。有捷径吗?

此外,如果可能的话,内联 CSS 比单独的 css 文件更可取。

谢谢 莎拉

编辑:

这是我的一些代码。你能告诉我我会把必要的 CSS 放在哪里吗?

body<-dashboardBody( tags$style(".content {background-color: black;}"),
useShinyjs(),
tags$style(type='text/css', ".skin-blue .main-header .logo {background-color: #000000}" ),
tags$style(type='text/css', ".skin-blue .main-header .logo:hover {background-color: #000000}"),
tags$style(type='text/css', ".skin-blue .main-header .navbar {background-color: #000000}"),
tags$style(type="text/css",".shiny-output-error { visibility: hidden; }",".shiny-output-error:before { visibility: hidden; }"),
fluidPage(
img(src="img2.PNG",height="100%", width="100%",style='padding:0px;'),
br(),br(),
tabBox("Menu Database", width = 12,
tabPanel("Menu Database", 
tabsetPanel(
tabPanel("LTO Survey results",

@David Kris的公认答案是绝对正确的,以防万一有人(像我一样(需要更多的阐述。 正如他的回答中提到的,插入代码

* { font-family: "Arial"; }

要么在

  1. 一个CSS文件(shiny.rstudio.com/articles/css.html(,对于那些懒惰的人(像我一样(:
  • 在您的应用程序目录中创建一个文件夹 www,
  • 使用上面的代码将bootstrap_custom.css文件放入其中,
  • 在 R 代码中,使用
ui <- dashboardPage(dashboardHeader(), dashboardSidebar(), dashboardBody(),
tags$head(tags$link(rel = "stylesheet", type = "text/css", href = "bootstrap_custom.css"))

  1. 直接进入您的 R 代码:
ui <- dashboardPage(dashboardHeader(), dashboardSidebar(), dashboardBody(),
tags$head(tags$style(HTML('* {font-family: "Arial"};'))))

您可以将所需的font-family放在body选择器中

body {
font-family: Arial;
}

或者使用通用选择器*将更改每个元素

* { font-family: Arial; }

好吧,这不是我最喜欢这样做的,但这将起作用。很确定你将不得不摇摆!important否则你会被某些元素的级联击败。

编辑:在一些网站上进行了测试以确认。没有!important就无法改变一切

.CSS:

* {
font-family: Arial, sans-serif !important;
}

*= 匹配所有元素

最新更新