Failing to render interactive Rmarkdown plotly figure in shiny

Viewed 175

I'm trying to render an interactive plotly graph that is already saved in an HTML file (after rendering it with Rmarkdown). I want to include this interactive HTML file to my shiny app. The app fails to show the plotly graph (it does exist as an HTML element, but it's just blank). However, when viewing only the HTML file in my browser it works.

See below for my code.

Any help is greatly appreciated.

library(shiny)
library(rmarkdown)

ui <- fluidPage(uiOutput("md_file"))

# Define server logic
server <- function(input, output, session) {

  # Just a simple interactive rmd example
  exampleRMD <- "
```{r}
library(viridis)
library(plotly)
plot_ly(z = ~volcano, type = 'heatmap')
```"

  # Save and render Rmd file.
  write(exampleRMD, "file.Rmd")
  render("file.Rmd", output_format = "html_document", output_file = "knitted.html")

  # Render html output
  output$md_file <- renderUI({ 
    includeHTML("knitted.html")
  })
}

# Run the application
shinyApp(ui = ui, server = server)
0 Answers
Related