html - 在 R Shiny App 中显示带有工作子链接的 HTML 文件
问题描述
我尝试在我的 R Shiny Dashboard App 中将现有的 HTML 文件显示为内容 - 与此问题类似。我的 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>
用户界面
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")))
)
)
)
)
服务器.R
library(shiny)
shinyServer(function(input, output) {
getPageMain<-function() {
return(includeHTML("C:/sub_link/main.html"))
}
output$html_main<-renderUI({getPageMain()})
})
解决方案
您可以使用iframe。这需要target = "_self"
在a标签中设置。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>
推荐阅读
- c++ - 绑定 API 在服务器程序中究竟做了什么
- sql - 如果具有这些名称的表存在,则执行联合
- objective-c - 为什么将此协议添加到此类别会触发编译器警告?
- python - CVXPY:解相等的目标函数
- css - 我需要将样式更改为具有类的 div 内所有出现的锚元素
- docker - Docker API /images/json 总是返回 Containers:-1
- go - go数据结构中的继承
- java - 如何检查 glassfish 上的 http 请求的完整响应时间?
- python - 在python中搜索查询
- speech-to-text - 使用其他数据重新训练 Azure 自定义语音模型