R SHINY display .html files includeHTML function

I have two HTML files (named default.html and index.html),
default.html contains a moving banner with three images (as below):


index.html contains HTML Scrolling Text
I want to read .html files with R Shiny,
but for some reason, an error occurs, and the images cannot be displayed correctly.

R Shiny code:

library(shiny)
ui <- shinyUI(
  fluidPage(
    h1("<<banner banner banner banner banner>>"),
    includeHTML("C:\\default.html"),
    includeHTML("C:\\index.html")
  )
)
server <- function(input, output) { } 
shinyApp(ui, server)

R error:

Warning messages:
1: `includeHTML()` was provided a `path` that appears to be a complete HTML document.
✖ Path: C:\default.html
ℹ Use `tags$iframe()` to include an HTML document. You can either ensure `path` is accessible in your app or document (see e.g. `shiny::addResourcePath()`) and pass the relative path to the `src` argument. Or you can read the contents of `path` and pass the contents to `srcdoc`. 
2: `includeHTML()` was provided a `path` that appears to be a complete HTML document.
✖ Path: C:\index.html
ℹ Use `tags$iframe()` to include an HTML document. You can either ensure `path` is accessible in your app or document (see e.g. `shiny::addResourcePath()`) and pass the relative path to the `src` argument. Or you can read the contents of `path` and pass the contents to `srcdoc`.

output:

three images(C:\banner1.jpg、C:\banner2.jpg、C:\banner3.jpg):



thanks a lot!

1 Like

it seems that you arent using an Rstudio Project to house your shiny application development work; I expect that this is a bad idea.

If you did make an RStudio Project for it, you could
a) more easily bundle assetts into the expected www subfolder of your project folder
b) gain many other benefits, like git integration for version control etc.

aside from that when the time comes to include your html, are they complete web pages or html fragments? the onscreen error message gives some info on that

Use `tags$iframe()` to include an HTML document. You can either ensure `path` is accessible in your app or document (see e.g. `shiny::addResourcePath()`) and pass the relative path to the `src` argument. Or you can read the contents of `path` and pass the contents to `srcdoc`.

Thank you for your reply. I have saved the .R file in C:\banner and placed all the images in C:\banner\www.

I don't understand what "complete web pages" and "html fragments" mean. The files default.html and index.html were both created locally (using Microsoft Expression Web 4 and Google Web Designer) and have not been published online.

I have also attempted to include the tags$iframe() and shiny::addResourcePath() as mentioned in the error, but have not been successful.

library(shiny)
ui <- shinyUI(
  fluidPage(h1("<<banner banner banner banner banner>>"),
    htmlOutput("output1")
    #,includeHTML("C:\\banner\\index.html")
    #,includeHTML("C:\\banner\\default.html")
  ))

#addResourcePath('banner', "./")
server <- function(input, output) { } 

output$output1 <- renderUI({
  tags$iframe(src="C:\\banner\\index.html", height = 600, width = 600)
})

shinyApp(ui, server)

My goal is to add a sliding banner when writing web pages in R. However, I couldn't find relevant syntax in R.So, I achieve the goal by reading .html files.

1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.