I am trying to build a quick application that displays a random HTML page but am running into problems with displaying the HTML. I believe this is related to R storing the character vectors with escape characters and shiny expecting non-escaped HTML, but I'm not positive on that.
I have a static data frame consisting of HTML page IDs and the corresponding HTML content that looks like this:
> str(dat)
'data.frame': 61 obs. of 2 variables:
$ msgid: chr "msgids..."
$ html : chr "html content..."
|
I also have a reactiveValue object that stores, among other things, the current email:
servervar <- reactiveValues()
And a function that grabs a random email to view, that looks like this:
grab.msg <- function() {
servervar[["msg"]] <- dat[sample(nrow(dat),1),]
}
I want to pass the html in my "servervar" reactiveValue object to UI so it can be printed (among other things). To do this I I'm using a renderText() function to return the html content:
output$msghtml <- renderText(function(){
servervar$msg[["html"]])
})
And then in the ui.R file I am attempting to display this html content via:
wellPanel(htmlOutput("msghtml"))
This almost works, but isn't quite there. The problem is that my html content has a bunch of escape characters from R and thus is not formed correctly. For example this HTML:
<HTML>
<p>some content</p>
<p> some more content </p>
</HTML>
Looks like this:
"\t\t<HTML>\t\t\t<p>some content</p>\t\t \t<p> some more content </p>\t\t</HTML>"
The escape characters are actually a bigger deal than just tabs (like in the example above), because some image links are broken completely and for some HTML pages Shiny throws a Javascript error and breaks down (the html pages load just fine when dragging into a browser). Does anyone have an idea about how to get around this issue? I tried using textOutput() instead of htmlOutput() in the ui.R file, but doesn't seem to work either.
Thanks!