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

Sar*_*hGC 5 html css fonts r shiny

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

我知道你可以在每个片段中添加 font-family 语句(例如: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",
Run Code Online (Sandbox Code Playgroud)

小智 9

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

 * { font-family: "Arial"; }
Run Code Online (Sandbox Code Playgroud)

要么在

  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"))
Run Code Online (Sandbox Code Playgroud)

或者

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


Dav*_*ris 6

你可以把font-family你想要的放在一个body选择器中

body {
  font-family: Arial;
}
Run Code Online (Sandbox Code Playgroud)

或者使用通用选择器*会改变每个元素

* { font-family: Arial; }
Run Code Online (Sandbox Code Playgroud)