简体   繁体   English

更改R Shiny fileInput中标签文本的大小/间距吗?

[英]Change the size /spacing of label text in R Shiny fileInput?

I am working on an R Shiny app, where I have constructed a file input function like so: 我正在开发R Shiny应用程序,在该应用程序中,我构建了如下文件输入功能:

  csvFileInput <- function(name_space, file_name="file", label = "Input file") {
    ns <- NS(name_space)
    # doc here: https://shiny.rstudio.com/reference/shiny/latest/fileInput.html
    fileInput(ns(file_name), label)
  }

Now I am trying to change the font settings of the label supplied here (in the image below, it is "File in"). 现在,我试图更改此处提供的label的字体设置(在下图中,它是“文件输入”)。 The font seems too large for longer labels and it sometimes looks clunky. 对于较长的标签,字体似乎太大了,有时显得笨拙。

  • Is there a way to change the font size in these labels? 有没有办法更改这些标签中的字体大小?

  • Is there a way to add whitespace such as tabs or linebreaks? 有没有办法添加制表符或换行符之类的空格?

The docs simply say that this label is 文档只是说这个label

Display label for the control, or NULL for no label. 显示控件的标签,或显示NULL(无标签)。

R Shiny屏幕截图

There have been other questions on SO regarding Shiny text rendering in general, but I am not sure that those labels are implemented similarly and I have no knowledge of web scripting, so any help is much appreciated. 总体上,还有其他关于“有光泽的文本呈现”的问题 ,但是我不确定这些标签的实现方式是否相同,并且我也不了解Web脚本,因此非常感谢您的帮助。

This article pretty neatly summarizes the three ways you can style Shiny with CSS. 本文巧妙地总结了使用CSS设置Shiny样式的三种方法。 If you end up styling more than a few elements, it's often best to add the CSS through a style sheet (ie an actual .css file), which in Shiny needs to be placed in a subdirectory named "www", which in turn is in your app directory. 如果最终要对多个元素进行样式设置,通常最好通过样式表(即实际的.css文件)添加CSS,在样式表中,该样式表需要放置在名为“ www”的子目录中,该子目录又是在您的应用目录中。

If you're styling just one element ("element" meaning a UI output from a function), and you want the styling to apply to the entire element, you can wrap the element in a div tag and use the style attribute like so: 如果仅对一个元素进行样式设置(“ element”表示从函数输出的UI),并且希望将样式应用到整个元素,则可以将该元素包装在div标签中,并使用style属性,如下所示:

div(
   fileInput("file1", "Choose CSV File",
               accept = c(
               "text/csv",
               "text/comma-separated-values,text/plain",
               ".csv")
   ), style="font-size:80%; font-family:Arial;"
)

If you only want to style one component of the element, as you've described, then you need to use the developer tools in your browser to figure out what HTML you can target for your styling. 如您所描述的,如果您只希望对元素的一个组件进行样式设置,则需要使用浏览器中的开发人员工具来确定样式设置所针对的HTML。 In the case of a fileInput label, an actual <label> HTML tag is our target. 对于fileInput标签,实际的<label> HTML标签是我们的目标。 If you'd rather avoid needing a stylesheet, then you can add the necessary CSS through the third approach described in the Shiny article, which is through the tags function. 如果您不想使用样式表,则可以通过Shiny文章中介绍的第三种方法(通过tags功能)添加必要的CSS。 You can add the following code to your UI (right at the top of fluidPage ) to change the font and add padding below the label: 您可以将以下代码添加到您的UI(在fluidPage顶部的fluidPage )以更改字体并在标签下方添加填充:

tags$head(
  tags$style(HTML(
    "label { font-size:80%; font-family:Times New Roman; margin-bottom: 
    20px; }"
  ))
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM