我想将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)
通过运行应用程序并键入数字,我们可以看到numericInput
和verbatimTextOutput
中的字体系列有所不同。
根据这个答案(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)
但是字体家族仍然不一样。
似乎我尚未使用正确的字体系列。请让我知道我如何实现这一目标。
答案 0 :(得分:2)
尝试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;
}"
)
)
)
Texture Documentation: ASDisplayNode
编辑
在Chrome中,如果右键单击并单击“检查”,然后向下滚动以找到相关的样式元素:
在右下角您可以看到: