gpt4 book ai didi

R Shiny : How to change background color of a table

转载 作者:行者123 更新时间:2023-12-03 20:42:00 27 4
gpt4 key购买 nike

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

用户界面

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

mainPanel(

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

tableOutput("dummy") ) ))


服务器

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



我得到的是这个

enter image description here

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

enter image description here

感谢大家的帮助!

最佳答案

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

)
)

我还邀请您阅读关于 Shiny google 组的讨论,其中展示了如何使用 驯鹿包以生成 html 表并将它们插入到 Shiny 的应用程序中。这允许更灵活地控制样式。

关于R Shiny : How to change background color of a table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21904188/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com