【问题标题】:Display HTML File with working Sub-Links in R Shiny App在 R Shiny App 中显示带有工作子链接的 HTML 文件
【发布时间】:2019-11-21 15:35:18
【问题描述】:

我尝试在我的 R Shiny Dashboard App 中将现有的 HTML 文件显示为内容 - 类似于 this question。我的 HTML 文件还包含指向我希望能够点击和关注的其他本地 HTML 文件的链接。

我设置了如下的最小示例。如果我单击 ma​​in.html 中的链接,我希望显示 target.html。目前,当我单击 ma​​in.html 中的链接时,我收到 Not Found 错误。

非常感谢任何帮助。

谢谢, 乔纳森

ma​​in.html

<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><title>Head</title></head>
<body><a href="target.html">target</a></body>
</html>

target.html

<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><title>Head</title></head>
<body><a href="main.html">back to main</a></body>
</html>

ui.R

library(shinydashboard)

dashboardPage(
    dashboardHeader(title = "HTML Main"),
    dashboardSidebar(
        sidebarMenu(
            menuItem("Main", tabName = "main")
        )
    ),
    dashboardBody(
        tabItems(
            tabItem(tabName = "main",
                fluidRow(box(width=NULL, htmlOutput("html_main")))
            )
        )
    )
)

server.R

library(shiny)

shinyServer(function(input, output) {
  getPageMain<-function() {
    return(includeHTML("C:/sub_link/main.html"))
  }
  output$html_main<-renderUI({getPageMain()})
})

【问题讨论】:

    标签: html r shiny shinydashboard


    【解决方案1】:

    您可以使用 iframe。这需要在 a 标签中设置target = "_self"。 html 文件必须位于 www 子文件夹中。

    ui <- dashboardPage(
      dashboardHeader(title = "HTML Main"),
      dashboardSidebar(
        sidebarMenu(
          menuItem("Main", tabName = "main")
        )
      ),
      dashboardBody(
        tabItems(
          tabItem(tabName = "main",
                  tags$iframe(src = "main.html")
          )
        )
      )
    )
    
    server <- function(input, output) {}
    
    shinyApp(ui, server)
    

    main.html

    <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
      <title>Head</title>
    </head>
    <body>
      <a href="target.html" target="_self">target</a>
    </body>
    </html>
    

    target.html

    <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
      <title>Head</title>
    </head>
    <body>
      <a href="main.html" target="_self">back to main</a>
    </body>
    </html>
    

    【讨论】:

    • 不幸的是,iFrame 对我来说是空白的。不知道为什么。
    猜你喜欢
    • 2014-09-12
    • 2020-07-13
    • 2018-03-16
    • 2022-09-27
    • 1970-01-01
    • 2021-10-31
    • 2020-07-31
    • 2023-03-12
    • 1970-01-01
    相关资源
    最近更新 更多