在 Shiny App 中更改文本的颜色和字体 [英] Change the color and font of text in Shiny App

查看:66
本文介绍了在 Shiny App 中更改文本的颜色和字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 server.R 中使用以下代码在主面板中显示文本.这正是它应有的工作方式.

I am using below code in server.R to display the text in the main panel. This is working exactly the way it should work.

output$text1 <- renderText({
  if(input$ag == 0) return(NULL)
  return('First 20 rows for requested AG')
})

有没有办法改变文字的字体和颜色?

Is there any way to change the font and color of the text?

推荐答案

你可以像@jbaums一样使用css

You can use css as @jbaums indicated

library(shiny)
runApp(list(
  ui = bootstrapPage(
    numericInput('n', 'Number of obs', 100),
    textOutput('text1'),
    tags$head(tags$style("#text1{color: red;
                                 font-size: 20px;
                                 font-style: italic;
                                 }"
                         )
              )
  ),
  server = function(input, output) {
    output$text1 <- renderText({ paste("hello input is",input$n) })
  }
))

通常您会将其包含在 styles.css 文件中,但它在此处显示为自包含文件.#text1 指的是id=text1的DOM元素,大括号内的内容就是相关的样式.

Normally you would include this in a styles.css file but it is shown inline here to be self contained. #text1 refers to the DOM element with id=text1 and the contents of the curly brackets are the relevant styles.

这篇关于在 Shiny App 中更改文本的颜色和字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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