【问题标题】:Display HTML file in Shiny App在 Shiny App 中显示 HTML 文件
【发布时间】:2014-09-12 14:21:57
【问题描述】:

是否可以在 Shiny 应用程序中(在主面板中)显示 html 文件?这个 HTML 是由 SAS 代码创建的,但我想在 Shiny App 中显示。这不是一个小图像。这是 HTML 文件中的表格输出。

Html 文件包含如下表格:

我们将不胜感激。

谢谢! 廷库

@MrFlick - 感谢您的电子邮件。流体页面不工作。它给出的错误消息是:

ERROR: could not find function "fluidPage"

titlePanel 也不起作用。

注意 - 当我使用 pageWithSidebar 代替 fluidPage 和 headerPanel 而不是 titlePanel 时,它可以正常工作。

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    如果您想在布局中包含来自另一个文件的 HTML 内容,只需使用 includeHTML() 函数。例如

    shinyUI(fluidPage(
      titlePanel("Included Content"),
      mainPanel(
        includeHTML("include.html")
      )
    ))
    

    应该至少足以让特定页面上的“include.html”的内容。如果你需要让它更有活力,你可以这样做

    #  ----- ui.R -----
    
    shinyUI(fluidPage(
      titlePanel("Uploading Files"),
      mainPanel(
        htmlOutput("inc")
      )
    ))
    
    #  ----- server.R -----
    
    shinyServer(function(input, output) {
      getPage<-function() {
          return(includeHTML("include.html"))
      }
      output$inc<-renderUI({getPage()})
    })
    

    你可以使用任何你想要的逻辑来指定你想要加载的文件名。

    【讨论】:

    • 我尝试代码时未呈现 HTML 脚本。我创建了一个示例 include.html 文件并将其放在与闪亮应用程序相同的文件夹中。谁能告诉我为什么它可能不起作用?
    【解决方案2】:

    适用于来自 Google 的任何人;最终提供了解决方案on Github

    您可以使用 iFrame 结构包含另一个 html 文件,如下所示:

    ui <- fluidPage(
      htmlOutput("map")
    )
    
    addResourcePath("tmpuser", getwd())
    server <- function(input,output){
        output$map <- renderUI({
          tags$iframe(seamless="seamless", 
                      src= "tmpuser/foo.html",
                      width=800, 
                      height=800)
         })
     }
    
    shinyApp(ui, server)
    

    如果有人像我一样需要在 tags$iframe() 中预滚动 iFrame 窗口 you can use an additional argument 的内容:

    onload= "this.contentWindow.document.documentElement.scrollLeft=820; this.contentWindow.document.documentElement.scrollTop=400"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-21
      • 2020-07-13
      • 1970-01-01
      • 2018-03-16
      • 1970-01-01
      • 2021-08-05
      • 2021-09-21
      • 1970-01-01
      相关资源
      最近更新 更多