Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display HTML file in Shiny App

Tags:

r

shiny

Is it possible to display a html file in Shiny app (in main panel)? This HTML is created by a SAS code but I want to display in Shiny App. This is not a small image. This is tabular output in HTML file.

Html file contains tabele as given below:

enter image description here

Any help will be highly appreciated.

Thanks! Tinku

@MrFlick - Thanks for your email. fluidPage is not working. It's giving the error message that:

ERROR: could not find function "fluidPage"

titlePanel is also not working.

Note - When I used pageWithSidebar instaed of fluidPage and headerPanel instead of titlePanel then it's workinmg fine.

like image 510
Piyush Avatar asked Jul 21 '14 22:07

Piyush


2 Answers

If you want to include HTML content from another file in a layout, just use the includeHTML() function. For example

shinyUI(fluidPage(
  titlePanel("Included Content"),
  mainPanel(
    includeHTML("include.html")
  )
))

should be minimally sufficient to how the contents of "include.html" on a particular page. If you need to make it more dynamic, you can do

#  ----- ui.R -----

shinyUI(fluidPage(
  titlePanel("Uploading Files"),
  mainPanel(
    htmlOutput("inc")
  )
))

#  ----- server.R -----

shinyServer(function(input, output) {
  getPage<-function() {
      return(includeHTML("include.html"))
  }
  output$inc<-renderUI({getPage()})
})

And you could use whatever logic you want to to specify the filename you want to load.

like image 135
MrFlick Avatar answered Nov 16 '22 16:11

MrFlick


For anyone coming from Google; the solution was eventually provided on Github.

You can include another html file using an iFrame construct like so:

ui <- fluidPage(
  htmlOutput("map")
)

addResourcePath("tmpuser", getwd())
server <- function(input,output){
    output$map <- renderUI({
      tags$iframe(seamless="seamless", 
                  src= "tmpuser/foo.html",
                  width=800, 
                  height=800)
     })
 }

shinyApp(ui, server)

If anyone, like me, needs to also pre-scroll the content of the iFrame window you can use an additional argument within tags$iframe():

onload= "this.contentWindow.document.documentElement.scrollLeft=820; this.contentWindow.document.documentElement.scrollTop=400"
like image 2
Anonymous Avatar answered Nov 16 '22 15:11

Anonymous