2014-10-19 37 views
1

晚上好,includeHTML for shiny,shinyApps.IO和Dropbox

快速問題,與R/shiny應用程序相關,託管在shinyApps.IO上。

我想要一個HTML文件駐留在我的Dropbox帳戶,並使用includeHTML將其包含在閃亮的應用程序中。這樣做的主要原因是我的本地機器有一個更新HTML文件(使用knitr生成)的過程,如果我可以從shinyApps.IO訪問它,我不必每次都上傳它已更新。現在

,對Dropbox的一個RDATA文件可以使用下面的命令序列讀取:

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)) 

這會將從Dropbox的一個RDATA數據文件,它適用於shinyApps.IO爲好。

現在,假設我想爲HTML文件做同樣的事情,然後將這個文件用includeHTML顯示在一個閃亮的應用程序中。有誰知道如何做到這一點?

任何建議,將理解的是,

菲利普

回答

3

下面是一個說明將收存箱的HTML有光澤的應用程序的最小例子。關鍵點是設置content(request, 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}) 
    } 
    ) 
) 

獨立ui.R和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}) 
}) 
+0

喜cdeterman - 非常感謝,你的榜樣效果很好。然而,一個複雜的問題是:一旦我嘗試將代碼分解成server.R和ui.R文件,我會得到:「錯誤:無法打開連接」。 有沒有辦法保持「2文件」結構? – PMaier 2014-10-20 19:09:21

+0

@PMaier,你有server.R文件中的請求和dropbox.html語句嗎? – cdeterman 2014-10-20 19:14:02

+0

cdeterman - 得到它的工作!我有一個自定義的CSS文件,搞砸了。再次感謝,這真的很酷! – PMaier 2014-10-20 19:34:07