如何更改某些textOutput元素的字体? [英] How to change the font of some textOutput elements?

查看:117
本文介绍了如何更改某些textOutput元素的字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在server.RI中,本周的大量指标以及以前测量的指标都存储在其中。

 输出$ x1_current_week<-renderText(values [[''x1']])
输出$ x2_current_week<-renderText(values [['x2']])
...
输出$ x1_previous_week<-renderText(values_previous_week [['x1']])
output $ x2_previous_week<-renderText(values_previous_week [['x2']])
...

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



下面显示的是我要实现的目标。我已经对上周的值进行了硬编码。





要实现此目标的ui代码如下:

  box(
...
html(< p align ='center'> ; x2< / p>),
h3(textOutput('x2_current_week'),align ='center'),
html(< p align ='center'>前一周:A< ; / br>)

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

解决方案

您可以将CSS添加到元素中与样式标签。 (或将它们包括为CSS文件,请参见


In server.R I have a bunch of metrics from this week stored in output as well as the previously measured metrics.

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']])
...

in my ui.R i want to display both the current and previous week's values in a box with the current week in the center using custom font/color defined in css and the previous week below it using the same font as just plain html.

Shown below is what I'm trying to achieve. I've hard coded the previous week value.

the ui code to achieve this is as follows

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

How do print the previous week's value in the html displayed font and add text around the value? I've tried using paste() but the textOutput is the only part that is displayed.

解决方案

You can add CSS to elements with style tags. (Or include them as a CSS file, see here.) I think this can guide you in the right direction:

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)

Hope this helps!

这篇关于如何更改某些textOutput元素的字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆