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

时间:2014-02-20 09:55:26

标签: r shiny

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

ui.R

  

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

     

mainPanel中(

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

tableOutput("dummy")   ) ))

server.R

  

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

我得到的是这个

enter image description here

我希望获得(我使用GIMP重新创建它)

enter image description here

感谢大家的帮助!

1 个答案:

答案 0 :(得分:15)

已在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)) }) 
  }

  )
)

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