[英]How to change the color of a box's collapse/expand button in R Shiny?
I cannot figure out how to change the color of the +/- button of the collapsible box.我不知道如何更改可折叠框的 +/- 按钮的颜色。 I want to change the white button to black.
我想将白色按钮更改为黑色。 Below is the sample code:
下面是示例代码:
library(shiny)
library(shinydashboard)
body <- dashboardBody(
fluidRow(
box(status = "info", solidHeader = TRUE, title = "Background - Hypothetical Life", width = "auto", collapsible = TRUE, collapsed = TRUE,
h5("sample text"))))
ui <- dashboardPage(
dashboardHeader(title = "Box"),
dashboardSidebar(),
body
)
server = function(input, output, session) { }
shinyApp(ui = ui, server = server)
Many thanks!非常感谢!
Here's how you can do it, with CSS:以下是使用 CSS 的方法:
library(shiny)
library(shinydashboard)
body <- dashboardBody(
tags$style(
type = 'text/css',
'.fa, .fas {
font-weight: 900;
color: black;
}'
),
fluidRow(
box(status = "info", solidHeader = TRUE,
title = "Background - Hypothetical Life",
width = "auto", collapsible = TRUE, collapsed = TRUE,
h5("sample text"))))
ui <- dashboardPage(
dashboardHeader(title = "Box"),
dashboardSidebar(),
body
)
server = function(input, output, session) { }
shinyApp(ui = ui, server = server)
As said in this answer , when you want to change something in the CSS style but don't really know CSS (like me), launch your app in browser, do "Inspect element" (right click or Ctrl+Shift+C for me) and check the "Inspector".如本答案所述,当您想更改 CSS 样式中的某些内容但并不真正了解 CSS(像我一样)时,请在浏览器中启动您的应用程序,执行“检查元素”(对我而言右键单击或 Ctrl+Shift+C) ) 并检查“检查员”。 It will show you the CSS description of each element.
它将向您显示每个元素的 CSS 描述。
Then, you put this CSS code in tags$style
like in the example above and you add some arguments to customize it.然后,像上面的示例一样,将此 CSS 代码放在
tags$style
中,并添加一些参数来自定义它。 There are many resources online on CSS.网上有很多关于 CSS 的资源。
For example, in the example above, I saw in the "Inspector" that the icon CSS style was:例如,在上面的示例中,我在“检查器”中看到图标 CSS 样式是:
.fa, .fas {
font-weight: 900;
}
So I just put it in a tags$style
and then searched what was the argument I needed to modify the color of the icon.所以我只是把它放在一个
tags$style
,然后搜索我需要修改图标颜色的参数是什么。 This answer to another post gave me solution: you need to add color
.这个对另一篇文章的回答给了我解决方案:你需要添加
color
。
Hope this helps希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.