【问题标题】:How to parse as HTML tag from server.R in Shiny如何在 Shiny 中从 server.R 解析为 HTML 标记
【发布时间】:2014-05-14 06:25:18
【问题描述】:

我要做的是解析从 server.R 的反应函数返回的 HTML 字符串。我已经尝试了几天来解决这个问题,但没有运气。例如,给定以下 ui.R 文件:

library(shiny)
shinyUI(pageWithSidebar( 
  headerPanel("Code"), 
  sidebarPanel(   
  ), 
  mainPanel(
    textOutput("code")
  )  
))

server.R文件:

shinyServer(function(input, output) {
  output$code <- renderText({   
    HTML('<strong> Hello World <strong>')
  }) 
})

我希望输出是:

你好世界

而不是显示强标记的原始 HTML 文本输出。

基本上,我希望在 ui.R 中解析 HTML 文本。我实际上正在尝试做一些比这更复杂的事情,但是一旦我解决了这个简单的问题,我应该会没事的。我不能只将 HTML 标记放在 ui.R 中,因为我希望它根据其他一些值进行更改。谢谢!

【问题讨论】:

  • 你可以用uiOutputrenderUI代替文字
  • 成功了,谢谢!你是救世主!我将发布作为其他人的答案。

标签: r shiny


【解决方案1】:

所有,感谢 StackOverflow 的好心人,我找到了解决方案。您只需像这样使用 renderUI 和 uiOutput:

服务器.R

shinyServer(function(input, output) {
  output$code <- renderUI({   
    HTML('<strong> Hello World <strong>')
  }) 
})

ui.R

library(shiny)
shinyUI(pageWithSidebar( 
  headerPanel("Code"), 
  sidebarPanel(   
  ), 
  mainPanel(
     uiOutput("code")
  )  
))

问题解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-07
    • 2019-03-03
    • 2021-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多