Reputation: 654
Good evening,
Quick question, related to an R/shiny app, hosted on shinyApps.IO.
I'd like to have an HTML file residing on my Dropbox account, and include it into a shiny app using includeHTML. The main reason for doing that is that I have a process for my local machine to update the HTML file (which is generated using knitr), and if I could access it from shinyApps.IO, I would not have to upload it every time it is updated.
Now, an RData file on Dropbox can be read in using the following sequence of commands:
load("my_dropbox_credentials.rdata") # assume that file exists
file.InputData <- "https://www.dropbox.com/s/SOMEDROPBOXCODE?dl=0"
data.input <- (GET(url = file.InputData))
load(rawConnection(data.input$content))
This loads an RData data file from Dropbox, and it works on shinyApps.IO as well.
Now, suppose I would like to do the same thing for an HTML file, which would then be displayed using includeHTML in a shiny app. Does anyone know how to accomplish this?
Any advice would be appreciated,
Philipp
Upvotes: 3
Views: 1323
Reputation: 19960
Here is a minimal example that demonstrates adding a dropbox html to a shiny app. The key points are setting the content(request, as="text")
and rendering the vector as text.
require(shiny)
require(httr)
request <- GET(url="https://dl.dropboxusercontent.com/s/rb0cnyfiz2fgdaw/hello.html")
dropbox.html <-content(request, as="text")
runApp(
list(
ui = fluidPage(
titlePanel("Dropbox HTML file"),
mainPanel(
htmlOutput("includeHTML")
)
),
server = function(input, output){
output$includeHTML <- renderText({dropbox.html})
}
)
)
Separate ui.R and server.R
ui.R
require(shiny)
shinyUI = fluidPage(
titlePanel("Dropbox HTML file"),
mainPanel(
htmlOutput("includeHTML")
)
)
server.R
require(shiny)
require(httr)
request <- GET(url="https://dl.dropboxusercontent.com/s/rb0cnyfiz2fgdaw/hello.html")
dropbox.html <-content(request, as="text")
shinyServer(function(input, output){
output$includeHTML <- renderText({dropbox.html})
})
Upvotes: 4