繁体   English   中英

在 R Shiny 应用程序中显示 HTML 文件和工作子链接

[英]Display HTML File with working Sub-Links in R Shiny App

我尝试将现有的 HTML 文件显示为我的 R Shiny 仪表板应用程序中的内容 - 与此问题类似。 我的 HTML 文件还包含指向其他本地 HTML 文件的链接,我也希望能够单击并关注。

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

非常感谢任何帮助。

谢谢,乔纳森

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</a></body>
</html>

目标.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()})
})

您可以使用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>

目标.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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM