首页 文章

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

提问于
浏览
14

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

ui.R

shinyUI(pageWithSidebar(headerPanel(“Dummy”),sidebarPanel(标签$ hr()),mainPanel(#这是我用来改变背景颜色的
list(标签$ head(标签$ 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 回答

  • 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表并将其插入闪亮的应用中 . 这允许更灵活地控制风格 .

相关问题