Here is some interesting/ annoying behavior. The below code is the "Hello world" of shiny apps (old faithful geyser), with only one addition in the UI:
includeHTML('https://bl.ocks.org/mbostock/e6f9e160585c153fa5ec543bd12b81e9')
)
I also split it into tabPanels for clarity.
That link above is to a standard D3 example on bl.ocks.org. However when it renders in shiny, the d3 block simply renders as "Not Found".
Any idea how to get around this and embed a website with d3 into shiny?
Full reproducible code:
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
tabsetPanel(
tabPanel("main",
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)),
## Illustrate that d3 does not render
tabPanel("no_d3",
includeHTML("https://bl.ocks.org/mbostock/e6f9e160585c153fa5ec543bd12b81e9")
)
))
# Define server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
# Run the application
shinyApp(ui = ui, server = server)