Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add bullet points in R Shiny's renderText?

Tags:

r

shiny

I'm using renderText to display some dynamic output in my Shiny web app. Now how can I include a bullet points in the dynamic output?

like image 822
mchen Avatar asked Apr 07 '14 21:04

mchen


People also ask

What are tags in shiny?

shiny::tags is a list of 110 functions. Each function builds a specific HTML tag. If you are familiar with HTML, you will recognize these tags by their names. You can build UI by using HTML tags.

How do you add text to the shiny app?

You can use tahs$h1() to h6() to add headings, or add text using textOutput(). You can add text using text within quotes(" ").

What is renderText?

An expression that returns an R object that can be used as an argument to cat . env. The environment in which to evaluate expr .

How do you show shiny text?

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] ).


1 Answers

Assuming you are using UI.R and not a custom HTML UI, you should be able to use either the HTML function or the tags function for this.

Please be advised I am writing this out of my head, so the code is untested.

HTML("<ul><li>...text...</li><li>...more text...</li></ul>")

Or

tags$div(
  tags$ul(
     tags$li("text")
  )
)

Update: I first missed the dynamic word in your question, which is why I only mentioned UI.R (thanks to @StephaneLaurent for pointing it out).

In order to make your bulleted list dynamic you should use renderUI in your server.R. This function expects the expression it wraps to be HTML. Then, you can specify in your UI.R where to put the list by using uiOutput.

The code would look more or less like this:

UI.R

#other elements before the list
uiOutput("myList")
#other elements after the list

server.R

output$myList <- renderUI(HTML("<ul><li>...text...</li><li>...more text...</li></ul>"))

You can find more information on renderUI in the docs, and a brief explanation about using it for dynamic UIs in the tutorial.

like image 176
Guillem Vicens Avatar answered Sep 19 '22 07:09

Guillem Vicens