Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stylize or format text in R Shiny Server

I have an app running on shiny server and I would like to format smalls parts of text without needing to manage the css/html for the entirety of the page.

Simple example:

In the ui.r, I have some lines of help text that I would like to stylize.

sidebarPanel(
 ...
 , helpText("<I>Can</I> <em>this</em> <strong>happen</strong>?")
 )

Which gives:

# Current Output: 
<I>Can</I> <em>this</em> <strong>happen</strong>?

#desired Output:
Can this happen?

The text is (understandably) rendered as a literal string.
Is there a function or command to force the HTML to be parsed?

like image 864
Ricardo Saporta Avatar asked Sep 27 '13 16:09

Ricardo Saporta


People also ask

How do I render a Shiny text in R?

Use renderText in server to tell Shiny how to build the text. You'll need to use the same name to refer to the text in both scripts (e.g., "min_max" ). Your text should use both the slider's min value (saved as input$range[1] ) and its max value (saved as input$range[2] ).

Is R Shiny hard to learn?

Along with Shiny elements, you can use HTML elements to stylize your content in your application. In my opinion, R Shiny is very easy to learn despite how powerful the tool is. If you're working on a side project or looking to add something to your portfolio, I highly recommend trying it out.

What are the main 2 parts of an R Shiny app?

A Shiny app consists of two parts, a user interface ( ui ) and an R session that runs code and returns results ( server ). These two parts can be in their own files called ui. R and server. R, or they can be combined into a single file called app.


1 Answers

Use this:

sidebarPanel(
 ...
 , HTML("<I>Can</I> <em>this</em> <strong>happen</strong>?")
 )

As an aside, you can even use renderText on the server side to build a full HTML output string, which can change, depending on your inputs. I often use this to post automated commentary (e.g. "The latest data release is y.... this is an increase of y, relative to the previous release...").

like image 163
PMaier Avatar answered Oct 12 '22 14:10

PMaier