我想要做的是解析从 server.R 的 react 函数返回的 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>') 
  })  
}) 

我希望输出是:

Hello World

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

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

请您参考如下方法:

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

服务器

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

用户界面
library(shiny) 
shinyUI(pageWithSidebar(  
  headerPanel("Code"),  
  sidebarPanel(    
  ),  
  mainPanel( 
     uiOutput("code") 
  )   
)) 

问题解决了。


评论关闭
IT干货网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!