如何更改某些 textOutput 元素的字体?

pmd*_*aly 3 css r shiny

在 server.RI 中有一堆本周的指标存储在输出中,以及之前测量的指标。

output$x1_current_week  <- renderText(values[['x1']])
output$x2_current_week  <- renderText(values[['x2']])
...
output$x1_previous_week <- renderText(values_previous_week[['x1']])
output$x2_previous_week <- renderText(values_previous_week[['x2']])
...
Run Code Online (Sandbox Code Playgroud)

在我的 ui.R 中,我想使用 css 中定义的自定义字体/颜色在当前周在中心的框中显示当前和前一周的值,并使用与纯 html 相同的字体在其下方显示前一周。

下面显示的是我正在努力实现的目标。我已经硬编码了前一周的值。

在此处输入图片说明

实现这一点的ui代码如下

box(
    ...
    html("<p align='center'>x2</p>"),
    h3(textOutput('x2_current_week'), align='center'),
    html("<p align='center'>previous week: A</br>")
   )
Run Code Online (Sandbox Code Playgroud)

如何在 html 显示字体中打印上周的值并在值周围添加文本?我试过使用 paste() 但 textOutput 是唯一显示的部分。

Flo*_*ian 5

您可以向带有样式标签的元素添加 CSS。(或将它们包含为 CSS 文件,请参见此处。)我认为这可以指导您朝着正确的方向前进:

ui <- shinyUI(
  fluidPage(
    tags$style("#x1_current_week {font-size:20px;
               color:red;
               display:block; }"),
    tags$style("#x1_previous_week {font-size:15px;
               display:block;
               bottom: 12px; 
               position:absolute;
               width: 100%;
               left:0px;}"),
    div(style="text-align:center;
        box-shadow: 10px 10px 5px #888888;
        width:200px;
        height:200px;
        padding-top:70px;
        position:relative;",
        textOutput("x1_current_week"),
        textOutput("x1_previous_week")
    )
  )
)

server <- function(input,output)
{
  output$x1_current_week  <- renderText("x1 this week")
  output$x1_previous_week <- renderText("x1 prev week")

}


shinyApp(ui,server)
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!

在此处输入图片说明