Guillem Vicens
Guillem Vicens

Reputation: 3996

Shiny with HTML UI:

I am converting a small legacy web that currently uses R, RApache and PHP to use only R and Shiny instead. One of the requirements is to use HTML UI instead of the regular Shiny UI.R.

I have a file that includes some HTML text that should be rendered as such in the webpage. Actually it is assigned to a <span> tag that has assigned as id textoIntro and as class shiny-text-output.

I can easily load the content of this file and assign it to the span using following code in server.R:

library(shiny)

shinyServer(function(input, output) {

    # loading file info
    introFile <- 'path/file.txt'
    textoIntro <- readChar(introFile, file.info(introFile)$size)

    output$textoIntro <- renderText({HTML(textoIntro)})
})

But by doing this the text is not considered by the browser as HTML. Instead it is shown as "raw text":

<p>lorem ipsum </p> dolor sit amet...

I need it to load as HTML, like this:

lorem ipsum dolor sit amet

I have already tried to use renderPrint, but the effect is the same.

I know there is the HTML Shiny function, but I understand it has to be used in conjunction with the tag function, which as far as I know is intended for UI.R.

Anyone can give me a hint on how to do this? Thanks a lot!

Upvotes: 4

Views: 3066

Answers (2)

Joe Cheng
Joe Cheng

Reputation: 8061

The class for your <span> tag should be shiny-html-output, not shiny-text-output.

Upvotes: 6

Kevin Ushey
Kevin Ushey

Reputation: 21285

You can try using renderUI -- this should return it as HTML.

Upvotes: 5

Related Questions