Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse as HTML tag from server.R in Shiny

Tags:

r

shiny

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!

like image 461
user3424789 Avatar asked Mar 21 '23 00:03

user3424789


1 Answers

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.

like image 61
user3424789 Avatar answered Mar 22 '23 23:03

user3424789