【问题标题】:R Shiny: How to change background color of a tableR Shiny:如何更改表格的背景颜色
【发布时间】:2014-03-21 04:22:47
【问题描述】:

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

ui.R

shinyUI(pageWithSidebar(
headerPanel("虚拟"),
侧边栏面板( 标签$hr() ),

主面板(

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

tableOutput("dummy")   ) ))

服务器.R

shinyServer(function(input, output) { output$dummy

我得到的是这个

而我想要得到的(我使用 GIMP 重新创建它)是

感谢大家的帮助!

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    已经在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 表格并将它们插入闪亮的应用程序。这样可以更灵活地控制样式。

    【讨论】:

    • 一个不错的方法,但它也用红色填充了表格右侧的所有空间。有什么适合表格宽度的解决方案?
    • @Rufo 好问题。我无法仅使用 jQuery 向表格添加样式,我不明白为什么它不起作用。
    • @Rufo 我现在修改了我的答案。
    猜你喜欢
    • 2021-09-16
    • 1970-01-01
    • 2018-01-04
    • 2013-11-16
    • 1970-01-01
    • 2023-03-04
    • 2019-02-11
    • 2018-11-11
    • 2018-10-14
    相关资源
    最近更新 更多