如何将verbatimTextOutput的字体系列更改为与Shiny和Shinydashboard中的输入相同?

问题描述 投票:0回答:1

我想将verbatimTextOutput的字体系列更改为与Shiny和Shinydashboard中的输入相同。这是一个例子。

# Load the packages
library(shiny)
library(shinydashboard)

# User Interface
ui <- dashboardPage(
    header = dashboardHeader(title = ""),
    sidebar = dashboardSidebar(
      sidebarMenu(
        menuItem(
          text = "Example",
          tabName = "tab1"
        )
      )
    ),
    body = dashboardBody(
      tabItems(
        tabItem(
          tabName = "tab1",
          fluidRow(
            column(
              width = 4,
              numericInput(inputId = "Number", label = "A numeric input", value = NA),
              strong("The same number as the numeric input"),
              verbatimTextOutput("Number_out")
            )
          )
        )
      )
    )
  )

server <- function(input, output, session){
  output$Number_out <- renderText(as.character(input$Number))
}

# Run the app
shinyApp(ui, server)

通过运行应用程序并输入数字,我们可以看到numericInputverbatimTextOutput中的字体系列不同。

enter image description here

基于此答案(https://stackoverflow.com/a/48037443/7669809)和此答案(https://stackoverflow.com/a/50784117/7669809),我如下编辑了脚本。

# Load the packages
library(shiny)
library(shinydashboard)

# User Interface
ui <- dashboardPage(
    header = dashboardHeader(title = ""),
    sidebar = dashboardSidebar(
      sidebarMenu(
        menuItem(
          text = "Example",
          tabName = "tab1"
        )
      )
    ),
    body = dashboardBody(
      tags$head(
        tags$style(
          HTML(
            '#Number_out {
            font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
            font-size: 12px;
            }'
          )
          )
        ),
      tabItems(
        tabItem(
          tabName = "tab1",
          fluidRow(
            column(
              width = 4,
              numericInput(inputId = "Number", label = "A numeric input", value = NA),
              strong("The same number as the numeric input"),
              verbatimTextOutput("Number_out")
            )
          )
        )
      )
    )
  )

server <- function(input, output, session){
  output$Number_out <- renderText(as.character(input$Number))
}

# Run the app
shinyApp(ui, server)

但是字体家族仍然不一样。

enter image description here

似乎我还没有使用正确的字体系列。请让我知道如何实现此目标。

html css r shiny shinydashboard
1个回答
0
投票

尝试font-family: 'Source Sans Pro','Helvetica Neue',Helvetica,Arial,sans-serif;

所以您的tags$head将是:

tags$head(
  tags$style(
    HTML(
      "#Number_out {
       font-family:  'Source Sans Pro','Helvetica Neue',Helvetica,Arial,sans-serif;
       font-size: 14px;
        }"
    )
  )
)

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.