1

UPDATE: I posted a related question here

I need to include an html file in shiny using includeHTML. The file is generated by rmarkdown, and has a large number of htmlWidgets.

Shiny is showing the html file, but the htmlWidgests are missing. The problem occurs only when includeHTML is in server.R, but works ok if includeHTLM is in ui.R. I need to update file.html so includeHTML must be used in a reactive context.

The file.rmd is somthing like this

---
title: "test"
author: "me"
date: '`r Sys.Date()`'
output: html_document 
---

```{r}
df<- data.frame(a = c(1:10), b = c(1:10)) 
rpivotTable::rpivotTable(df , rows = 'a'   , cols= 'b' )  
rpivotTable::rpivotTable(df , rows = 'a'   , cols= 'b' )  
rpivotTable::rpivotTable(df , rows = 'a'   , cols= 'b' )  
```

then render to file.html

rmarkdown::render(  input = 'file.RMD'   ) 

This shiny app is OK

ui <- shinyUI(
  fluidPage(
    includeHTML('file.html')
  )
)
server <- function(input, output) { } 
shinyApp(ui, server)

BUT this one does not work.

ui <- shinyUI(
  fluidPage(
    uiOutput('tables')
  )
)

server <- shinyServer(function(input, output) {  
  output$tables <- shiny::renderUI(   
      includeHTML('file.html')  
   ) 
})

shinyApp(ui, server)
Community
  • 1
  • 1
Eduardo Bergel
  • 2,685
  • 1
  • 16
  • 21
  • Can you please check again? It actually works for me. – amrrs Aug 18 '16 at 17:52
  • Maybe we are using different versions of shiny? I am using v‘0.13.2’. Just in case I updated all packages to the latest version, Still not working for me. Also it does work if the html file is rendered with PNGs, but it fails when rendering the javascript htmlWidgets. – Eduardo Bergel Aug 18 '16 at 18:28
  • I am getting these errors in the browser console:data:application/x-javascript;base64,KGZ1bwCg==?_=14715.. 44615229 Failed to load resource: net::ERR_INVALID_URL – Eduardo Bergel Aug 18 '16 at 18:29
  • I'm sorry I checked the shiny code with a different file.html – amrrs Aug 18 '16 at 20:38
  • I am guessing dependencies are not transferred or are not being accepted. Do you know which `htmlwidgets` you will use in advance? For instance, do you know you will only be creating `rpivotTable`? If so, we can specify these in advance. – timelyportfolio Aug 20 '16 at 11:20
  • yes, I know in advanced wich htmlwidgets will be used. How can I specify the dependencies in advanced? – Eduardo Bergel Aug 20 '16 at 17:24

1 Answers1

0

Just getting a chance to dig into this, and the error I am getting is with the window.buildTabsets() from these lines.

Fix in YAML

If I render using these yaml options to disable the bootstrap, I get the expected result, but we lose bootstrap.

--- 
title: "test"
author: "me"
date: '`r Sys.Date()`'
output:
  html_document:
    theme: null
    mathjax: null
---

Confirm?

If possible, will you please verify that this also works on your side?

Better Approach?

In general, I would recommend a different approach, since the rendered html will contain all dependencies, and will be a very large file that gets passed across the websocket. Perhaps, this issue can help describe a potentially better approach.

timelyportfolio
  • 6,479
  • 30
  • 33
  • Thanks a lot for the additional info on this problem. Adding these yaml options does not work for me. – Eduardo Bergel Aug 25 '16 at 18:59
  • However, because it does not seem easy to resolve I am leaning toward implementing another approach as you suggested. I am now generating the output for shiny, and using RMD only for the reports. Is not as convenient for my use case, but seems to be less error prone. I guess that renderUI is still an experimental feature as stated in the documentation. – Eduardo Bergel Aug 25 '16 at 19:07