使用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")
}
)
答案 0 :(得分: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")) )
}
)