han*_*ick 5 html anchor r hyperlink shiny
我有一个Shiny App,它构建了一个很棒的HTML报告.我希望浏览报告对用户来说很容易.理想情况下,我想根据用户输入值"指向"特定的锚点.
library(shiny)
ui <- fluidPage(
htmlOutput("formattedText")
)
server <- function(input, output) {
output$formattedText <- renderText({
"<hr><br>Some text bla bla <br>Some text bla bla <br>
<hr><br>Some text bla bla<br>Some text bla bla <br>
<hr><br>Some text bla bla<br>Some text bla bla <br>
<hr><br>Some text bla bla<br>Some text bla bla <br>
<hr><br>Some text bla bla<br>Some text bla bla <br>
<hr><br>Some text bla bla<br>Some text bla bla <br>
<hr><br>Some text bla bla<br>Some text bla bla <br>
<hr><br>Some text bla bla<br>Some text bla bla <br>
<hr><br>Some text bla bla<br>Some text bla bla <br>
<hr><br>Some text bla bla<br>Some text bla bla <br>
<hr><br><a id='anchorid'></a>Point to this anchor<br>
<hr><br>Some text bla bla<br>Some text bla bla <br>
<hr><br>Some text bla bla<br>Some text bla bla <br>
<hr><br>Some text bla bla<br>Some text bla bla <br>
<hr><br>Some text bla bla<br>Some text bla bla <br>
<hr><br>Some text bla bla<br>Some text bla bla <br>
<hr><br>Some text bla bla<br>Some text bla bla <br>"
})
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)
此代码显示HTML报告的顶部.如何在锚点显示HTML报告:id = anchorid?
您需要在 HTML 代码中放置相应的链接。
目前您的 ShinyApp 输出产生:
<hr><br><a id='anchorid'></a>Point to this anchor<br>
Run Code Online (Sandbox Code Playgroud)
这是行不通的,因为您将链接定位在您希望链接吸引站点访问者的位置。因此,将该行更改为:
<hr><br><span id="anchorid">Point to this anchor</span><br>
Run Code Online (Sandbox Code Playgroud)
这会将这个特定点变成您的“书签”。为了使其工作,您需要一个链接供您的网站访问者点击。如果链接在同一个 HTML 文档中,请使用:
<a href="#anchorid">Go to this anchor</a>
Run Code Online (Sandbox Code Playgroud)
如果链接在不同的页面上,请使用:
<a href="thispage.html#anchorid">Go to this anchor</a>
Run Code Online (Sandbox Code Playgroud)
在W3C规范进入更详细。
| 归档时间: |
|
| 查看次数: |
335 次 |
| 最近记录: |