【问题标题】:Change font color in Shiny tableOutput更改 Shiny tableOutput 中的字体颜色
【发布时间】:2018-09-12 14:57:52
【问题描述】:

使用 tableOutput 更改单行数据框字体颜色的最简单方法是什么?具体来说,如何将“Right”下的“7”改为绿色。

library(shiny)

shinyApp(
  ui = fluidPage(

    sidebarLayout(
      sidebarPanel(
      fluidRow(  
         tableOutput("view")
        )
      ),

      mainPanel(
      ))),

  server = function(input, output, session){

    correct <- reactiveValues(num = 7)
    wrong <- reactiveValues(num = 4)   
    skipped <- reactiveValues(num = 9)

    togo = 80

    output$view <- renderTable(tibble(
      Right = correct$num,
      Wrong = wrong$num,
      Skipped = skipped$num,
      ToGo = togo
    ), spacing = "xs")
  }
)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    在这种情况下最好使用DT 附带renderDataTable 以获得更好的格式。

    library(shiny)
    library(tidyverse)
    library(DT)
    
    shinyApp(
      ui = fluidPage(
    
        sidebarLayout(
          sidebarPanel(
            fluidRow(  
              column(8,dataTableOutput("view"))
            )
          ),
    
          mainPanel(
          ))),
    
      server = function(input, output, session){
    
        correct <- reactiveValues(num = 7)
        wrong <- reactiveValues(num = 4)   
        skipped <- reactiveValues(num = 9)
    
        togo = 80
    
        output$view <- renderDataTable(datatable(tibble(
          Right = correct$num,
          Wrong = wrong$num,
          Skipped = skipped$num,
          ToGo = togo
        )) %>% formatStyle("Right",color=styleEqual(7, "red")) ) 
      }
    )
    

    仅显示表格:

    library(shiny)
    library(tidyverse)
    library(DT)
    
    shinyApp(
      ui = fluidPage(
    
        sidebarLayout(
          sidebarPanel(
            fluidRow(  
              column(8,dataTableOutput("view"))
            )
          ),
    
          mainPanel(
          ))),
    
      server = function(input, output, session){
    
        correct <- reactiveValues(num = 7)
        wrong <- reactiveValues(num = 4)   
        skipped <- reactiveValues(num = 9)
    
        togo = 80
    
        output$view <- renderDataTable(datatable(tibble(
          Right = correct$num,
          Wrong = wrong$num,
          Skipped = skipped$num,
          ToGo = togo
        ), options = list(dom = 't')) %>% formatStyle("Right",color=styleEqual(7, "red")) ) 
      }
    )
    

    【讨论】:

    • 这个选项带来了很多我想隐藏的功能。是否可以隐藏:显示条目 、搜索框、列名旁边的向上/向下小箭头、行名、“显示 1 到 1 个条目”和上一个/下一个?
    • 太棒了。谢谢。不过仍然有那些矫枉过正的三角形。
    猜你喜欢
    • 2014-07-25
    • 2018-01-23
    • 2021-11-14
    • 2018-10-22
    • 1970-01-01
    • 2016-11-30
    • 2013-11-14
    • 2014-01-19
    • 2015-01-02
    相关资源
    最近更新 更多