Piy*_*ush 32 fonts styles r shiny
我使用下面的代码在server.R主面板中显示文本.这正是它应该工作的方式.
output$text1 <- renderText({
if(input$ag == 0) return(NULL)
return('First 20 rows for requested AG')
})
Run Code Online (Sandbox Code Playgroud)
有没有办法改变文字的字体和颜色?
jdh*_*son 38
您可以使用css作为@jbaums指示
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) })
}
))
Run Code Online (Sandbox Code Playgroud)
通常你会将它包含在一个styles.css文件中,但它在这里显示为自包含.#text1指的是DOM元素,id=text1大括号的内容是相关的样式.
ath*_*shi 30
如果只想更改返回字符串的某个部分,可以使用htmlOutput而不是textOutput
在服务器端只返回
output$text1 <- renderText({ paste("hello input is","<font color=\"#FF0000\"><b>", input$n, "</b></font>") })
Run Code Online (Sandbox Code Playgroud)
通过这种方式,Shiny UI将执行HTML.
小智 22
在ui.r:
span(textOutput("message"), style="color:red")
Run Code Online (Sandbox Code Playgroud)
在server.r:
output$message <- renderText({"This is some red text"})
Run Code Online (Sandbox Code Playgroud)
@MikeP的解决方案还可以与p()fx一起使用p("some text", style = "color:red),因此,renderText()如果要动态显示它,也可以将其包装在服务器中。
| 归档时间: |
|
| 查看次数: |
56162 次 |
| 最近记录: |