代码之家  ›  专栏  ›  技术社区  ›  ixodid

更改闪亮表格输出中的字体颜色

  •  0
  • ixodid  · 技术社区  · 7 年前

    使用TableOutput更改单行数据框的字体颜色最简单的方法是什么?具体来说,如何将“右”下的“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")
      }
    )
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   amrrs    7 年前

    最好用一下 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")) ) 
      }
    )
    
    推荐文章