【问题标题】:includeHTML for shiny, shinyApps.IO and Dropbox包括闪亮的、闪亮的Apps.IO 和 Dropbox 的 HTML
【发布时间】:2014-12-14 08:11:50
【问题描述】:

晚上好,

关于 R/shiny 应用程序的快速问题,托管在 shinyApps.IO 上。

我想在我的 Dropbox 帐户中保存一个 HTML 文件,并使用 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 显示该文件。有谁知道如何做到这一点?

任何建议将不胜感激,

菲利普

【问题讨论】:

    标签: r dropbox shiny


    【解决方案1】:

    这是一个演示如何将 Dropbox 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")
      )
    )
    

    服务器.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})
    })
    

    【讨论】:

    • 您好 cdeterman - 非常感谢,您的示例运行良好。但是,有一个复杂情况:一旦我尝试将代码分解为 server.R 和 ui.R 文件,我得到:“错误:无法打开连接”。有没有办法保持“2文件”结构?
    • @PMaier,server.R 文件中有 request 和 dropbox.html 语句吗?
    • cdeterman - 让它工作!我有一个自定义 CSS 文件把事情搞砸了。再次感谢,这真的很酷!
    猜你喜欢
    • 1970-01-01
    • 2013-08-25
    • 2016-12-18
    • 2014-08-22
    • 2014-09-12
    • 2020-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多