【问题标题】:R Shiny: Formatting text within tableOutputR Shiny:在tableOutput中格式化文本
【发布时间】:2018-09-03 14:02:08
【问题描述】:

考虑以下非常简单的闪亮应用程序,它输出存储在数据框df 中的文本表:

library(shiny)

df <- data.frame(id=1:3,
                   text=c('It was a good day today', 'It is good to hear from you', 'I am feeling good'),
                   stringsAsFactors = FALSE)

ui <- fluidPage(
  tableOutput("freetext")
)

server <- function(input, output){
  output$freetext <- renderTable({ df })
}

shinyApp(ui=ui, server=server)

我希望每行中的“好”一词以红色显示。这可以使用tableOutput吗?

我看到诸如this one 之类的帖子建议在ui 函数中将htmlOutput 替换为htmlOutput,但我不知道如何将其扩展到文本表。

【问题讨论】:

    标签: r shiny format output


    【解决方案1】:

    如果您使用htmlTable,您可以在表格中包含一些 HTML。例如:

    library(shiny)
    library(htmlTable)
    
    df <- data.frame(
      id=1:3,
      text=c('It was a <span style="color:red;">good</span> day today', 
             'It is good to hear from you', 
             'I am feeling good'),
      stringsAsFactors = FALSE)
    
    ui <- fluidPage(
      htmlTableWidgetOutput("freetext")
    )
    
    server <- function(input, output){
      output$freetext <- renderHtmlTableWidget({ 
        htmlTableWidget(df) 
      })
    }
    
    shinyApp(ui=ui, server=server)
    

    【讨论】:

      猜你喜欢
      • 2013-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-29
      • 2018-04-13
      • 1970-01-01
      • 1970-01-01
      • 2016-06-28
      相关资源
      最近更新 更多