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.
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?
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] ).
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.
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.
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...").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With