Change the color and font of text in Shiny App

前端 未结 4 1819
心在旅途
心在旅途 2020-12-08 04:19

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 <- rend         


        
相关标签:
4条回答
  • 2020-12-08 04:41

    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) })
      }
    ))
    

    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.

    0 讨论(0)
  • 2020-12-08 04:56

    The solution by @MikeP also works with p(), fx p("some text", style = "color:red), so you can also just wrap that in a renderText() from the server if you want to display it dynamically.

    0 讨论(0)
  • 2020-12-08 04:58

    in ui.r:

    span(textOutput("message"), style="color:red")
    

    in server.r:

    output$message <- renderText({"This is some red text"})
    
    0 讨论(0)
  • 2020-12-08 04:59

    If only want to change a certain part of the returning string, one can use htmlOutput instead of textOutput

    On server side just return

    output$text1 <- renderText({ paste("hello input is","<font color=\"#FF0000\"><b>", input$n, "</b></font>") })
    

    In this way, Shiny UI will perform HTML.

    0 讨论(0)
提交回复
热议问题