R Shiny:如何更改表格的背景颜色

时间:2022-11-23 09:03:19

I found how to change the background color of the User Interface in Shiny. The withdraw I found is that it also colors the background of the tables i'm showing with tableOutput. Here I show a dummy example.

我找到了如何在Shiny中更改用户界面的背景颜色。我发现的撤销是它还使用tableOutput显示我正在显示的表格的背景。这里我展示一个虚拟的例子。

ui.R

ui.R

shinyUI(pageWithSidebar(
headerPanel("Dummy"),
sidebarPanel( tags$hr() ),

shinyUI(pageWithSidebar(headerPanel(“Dummy”),sidebarPanel(标签$ hr()),

mainPanel(

mainPanel中(

# This is what I use to change the background color
list(tags$head(tags$style("body {background-color: #ADD8E6; }"))),

tableOutput("dummy")   ) ))

server.R

server.R

shinyServer(function(input, output) { output$dummy <- renderTable({ data.frame(A=1:4,B=2:5,C=rep("aaa",4)) }) })

shinyServer(函数(输入,输出){output $ dummy < - renderTable({data.frame(A = 1:4,B = 2:5,C = rep(“aaa”,4))})})

What I get is this

我得到的就是这个

R Shiny:如何更改表格的背景颜色

and what I would like to get (I used GIMP to recreate it) is

我想得到什么(我使用GIMP重新创建)是

R Shiny:如何更改表格的背景颜色

Thanks everyone for your help!

谢谢大家的帮助!

1 个解决方案

#1


12  

A solution has been given on the shiny google group:

已经在闪亮的谷歌群体上给出了一个解决方案:

runApp(
  list(ui = bootstrapPage(pageWithSidebar(
    headerPanel("Rummy"),
    sidebarPanel( tags$hr() ),

    mainPanel(

      tableOutput("dummy"),
      # change style:    
      tags$head(tags$style("#dummy table {background-color: red; }", media="screen", type="text/css"))
    )

  )
  )

  ,
  server = function(input, output) {
    output$dummy <- renderTable({ data.frame(A=1:4,B=2:5,C=rep("aaa",4)) }) 
  }

  )
)

I also invite you to read this discussion on the shiny google group, which shows how to use the pander package to generate html tables and insert them in a shiny app. This allows a more flexible control of the style.

我还邀请您阅读有关闪亮的Google群组的讨论,该群组展示了如何使用pander包生成html表并将其插入闪亮的应用中。这允许更灵活地控制风格。

#1


12  

A solution has been given on the shiny google group:

已经在闪亮的谷歌群体上给出了一个解决方案:

runApp(
  list(ui = bootstrapPage(pageWithSidebar(
    headerPanel("Rummy"),
    sidebarPanel( tags$hr() ),

    mainPanel(

      tableOutput("dummy"),
      # change style:    
      tags$head(tags$style("#dummy table {background-color: red; }", media="screen", type="text/css"))
    )

  )
  )

  ,
  server = function(input, output) {
    output$dummy <- renderTable({ data.frame(A=1:4,B=2:5,C=rep("aaa",4)) }) 
  }

  )
)

I also invite you to read this discussion on the shiny google group, which shows how to use the pander package to generate html tables and insert them in a shiny app. This allows a more flexible control of the style.

我还邀请您阅读有关闪亮的Google群组的讨论,该群组展示了如何使用pander包生成html表并将其插入闪亮的应用中。这允许更灵活地控制风格。