Andy
Andy

Reputation: 292

R shiny using iframe for local files

I would like to have a tab in my shiny app link to an R help file on my local machine. Here is my attempt:

In server.r:

output$help <- renderUI({
  tags$iframe(
  seamless="seamless",
  src="file:///usr/lib64/R/library/r_package/html/r_function.html")
})

In ui.r:

mainPanel(
  tabsetPanel(id="tabSelected",
  tabPanel("Help", htmlOutput('help')))
)    

I am basically seeing a blank page. I replaced the link above with a pdf from a webpage and it shows it fine. So I am guessing it has something to do with how I am importing the local html file. Any help is greatly appreciated.

Thanks!

Upvotes: 8

Views: 6691

Answers (2)

Ramnath
Ramnath

Reputation: 55695

You should be able to use addResourcePath to do the needful. This will map the paths. accordingly. Adding them to the www folder will also work, but you would need to move the files first.

addResourcePath("library", "~/lib64/R/library")
output$help <- renderUI({
  tags$iframe(
  seamless="seamless",
  src="library/r_package/html/r_function.html")
})

Upvotes: 20

Julien Navarre
Julien Navarre

Reputation: 7830

When pages are loaded with a HTTP(S) protocol (the case of the Shiny app) for security reasons you can't framed locals files with their file: URLs. If you want to display locals files you should access to them with a http(s): URL, so you have to save them in your www directory (a local web server) and access to files with their http(s): URLs (the URL will be something like http://localhost/.../r_function.html).

Upvotes: 3

Related Questions