首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >是否可以将progressBar()在ShinyWidgets中的颜色更改为自定义颜色?

是否可以将progressBar()在ShinyWidgets中的颜色更改为自定义颜色?
EN

Stack Overflow用户
提问于 2018-03-26 15:15:02
回答 2查看 1.1K关注 0票数 4

我想将progressBar()颜色从shinyWidgets更改为自定义颜色。我知道有一些默认的颜色可以随状态而改变,但我想将其更改为不可用的颜色。

我是CSS的新手,所以我检查了git存储库本身的这里,看看是否可以覆盖CSS。我试图用(就在progressBar()之前添加的)覆盖CSS:

代码语言:javascript
运行
复制
tagss$style('.progress-bar-status{color: #25c484;
                background-color: #25c484;}')

但没起作用。有人知道怎么做吗?谢谢。

EN

回答 2

Stack Overflow用户

发布于 2018-03-26 15:26:02

您可以使用自定义status并定义相应的CSS,如下所示:

代码语言:javascript
运行
复制
library("shiny")
library("shinyWidgets")

ui <- fluidPage(
  column(
    width = 7,
    tags$b("Other options"), br(),
    progressBar(
      id = "pb2",
      value = 0,
      total = 100,
      title = "",
      display_pct = TRUE, 
      status = "custom"
    ),
    tags$style(".progress-bar-custom {background-color: #25c484;}"),
    actionButton(
      inputId = "go",
      label = "Launch calculation"
    )
  )
)

server <- function(input, output, session) {

  observeEvent(input$go, {
    for (i in 1:100) {
      updateProgressBar(
        session = session,
        id = "pb2",
        value = i, total = 100
      )
      Sys.sleep(0.1)
    }
  })
}

shinyApp(ui = ui, server = server)
票数 3
EN

Stack Overflow用户

发布于 2018-03-26 15:21:34

您的解决方案几乎可以工作,但是您应该修改progress-bar类的属性,例如:

代码语言:javascript
运行
复制
tags$head(tags$style(HTML('.progress-bar {background-color: red;}')))

我从这里的例子中发现了这一点,并将Sys.sleep语句修改为60秒,这样我们就可以更容易地检查页面。

下面给出了一个工作示例,希望这会有所帮助!

代码语言:javascript
运行
复制
server <- function(input, output) {
  output$plot <- renderPlot({
    input$goPlot # Re-run when button is clicked

    # Create 0-row data frame which will be used to store data
    dat <- data.frame(x = numeric(0), y = numeric(0))

    withProgress(message = 'Making plot', value = 0, {
      # Number of times we'll go through the loop
      n <- 10

      for (i in 1:n) {
        # Each time through the loop, add another row of data. This is
        # a stand-in for a long-running computation.
        dat <- rbind(dat, data.frame(x = rnorm(1), y = rnorm(1)))

        # Increment the progress bar, and update the detail text.
        incProgress(1/n, detail = paste("Doing part", i))

        # Pause for 0.1 seconds to simulate a long computation.
        Sys.sleep(0.5)
      }
    })

    plot(dat$x, dat$y)
  })
}

ui <- shinyUI(basicPage(
  tags$head(tags$style(HTML('.progress-bar {background-color: red;}'))),
  plotOutput('plot', width = "300px", height = "300px"),
  actionButton('goPlot', 'Go plot')
))

shinyApp(ui = ui, server = server)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49494891

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档