4
votes

What I am trying to do is parse at HTML string returned from a reactive function from server.R. I have tried for several days to solve this but no luck. For instance, given the following ui.R file:

library(shiny)
shinyUI(pageWithSidebar( 
  headerPanel("Code"), 
  sidebarPanel(   
  ), 
  mainPanel(
    textOutput("code")
  )  
))

and server.R file:

shinyServer(function(input, output) {
  output$code <- renderText({   
    HTML('<strong> Hello World <strong>')
  }) 
})

I would like the output to be:

Hello World

Instead of the raw HTML text output showing the strong tag.

Essentially, I would like to have the HTML text parsed in the ui.R. I am actually trying to do something more complex than this, but once I get this simple problem solved, I should be OK. I can't just put the HTML tag within the ui.R, because I would like it to change based on some other values. Thank you!

1
You can use uiOutput and renderUI instead of text - Julien Navarre
That worked, thanks! You are a savior! I will post as an answer for the rest to see. - user3424789

1 Answers

7
votes

All, I have found the solution thanks to kind soul over at StackOverflow. You just use renderUI and uiOutput as such:

server.R

shinyServer(function(input, output) {
  output$code <- renderUI({   
    HTML('<strong> Hello World <strong>')
  }) 
})

ui.R

library(shiny)
shinyUI(pageWithSidebar( 
  headerPanel("Code"), 
  sidebarPanel(   
  ), 
  mainPanel(
     uiOutput("code")
  )  
))

Question solved.