在R Shiny App中显示带有有效子链接的HTML文件

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

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

我们非常感谢您的帮助。

谢谢, 乔纳森

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>

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()})
})
lqlqtotti 回答:在R Shiny App中显示带有有效子链接的HTML文件

您可以使用 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>
本文链接:https://www.f2er.com/3056821.html

大家都在问