Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the color and font of text in Shiny App

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?

like image 445
Piyush Avatar asked Jun 04 '14 23:06

Piyush


People also ask

How do I change the color of my text font?

Go to Format > Font > Font. + D to open the Font dialog box. Select the arrow next to Font color, and then choose a color.

How do you bold text in the shiny app?

Shiny has many functions that can transform plain text into formatted text. Simply place text inside the h1() function to create a primary header (e.g. a title), h2() for a secondary header, strong() to make text bold, em() to make text italicized, or any of the other formatting functions.

How do you change the color of your text for apps?

Open your device's Settings app . Text and display. Select Color correction. Turn on Use color correction.

How do you change font color in R studio?

Navigate to Tools > Global Options > Appearance.


2 Answers

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.

like image 198
jdharrison Avatar answered Oct 05 '22 01:10

jdharrison


in ui.r:

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

in server.r:

output$message <- renderText({"This is some red text"}) 
like image 43
MikeP Avatar answered Oct 05 '22 00:10

MikeP