R Shiny includeHTML missing htmlWidgets in a reactive context

不羁岁月 提交于 2019-12-18 09:26:56

问题


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)

回答1:


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.



来源:https://stackoverflow.com/questions/39024390/r-shiny-includehtml-missing-htmlwidgets-in-a-reactive-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!