首页 > 解决方案 > 有没有办法用 Shiny R 在 textInput 中放置超链接

问题描述

对于我目前正在处理的项目,我想使用闪亮的 R 在 textInput 框中放置一个超链接。在 R 中使用以下脚本时,我的 html 代码显示在 textInput 框中,而不是将“Google 主页”显示为可点击关联。


test <- a("Google Homepage", href="https://www.google.com/")

runApp(
    list(ui = fluidPage(
         textInput("test", "test", test)
    ),
    server = function(input, output, session){
    })
)

是否可以在 textInput 框中放置超链接?还是仅作为输出值?

标签: rurlshinytextinput

解决方案


正如@Stéphanie 提到的,这是不可能的。因为您将 a 标签作为输入元素的值包含在内。如果您查看 HTML,您将看到:

<input id="test" type="text" class="form-control shiny-bound-input" value="<a href=&quot;https://www.google.com/&quot;>Google Homepage</a>">

因此,如果您只想要一个可点击的链接,则不需要textInput. 只需a tag放入fluidPage

test <- a("Google Homepage", href="https://www.google.com/")

runApp(
  list(ui = fluidPage(
    test
  ),
  server = function(input, output, session){
  })
)

推荐阅读