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

2023-11-21

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

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

此外,如果可能的话,内联 CSS 优于单独的 css 文件。

谢谢, 莎拉

Edit:

这是我的一些代码。你能告诉我在哪里放置必要的 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"))

OR

  1. 直接进入你的 R 代码:
ui <- dashboardPage(dashboardHeader(), dashboardSidebar(), dashboardBody(),
                  tags$head(tags$style(HTML('* {font-family: "Arial"};'))))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

更改整个 R Shiny 应用程序的字体系列:CSS/HTML 的相关文章

随机推荐