r - 更改下载按钮的背景颜色

标签 r shiny

如何更改下方按钮的背景颜色。

这是您可以运行的代码,您可以看到按钮背景仍然是白色,但他的颜色是绿色

用户界面

library(shinydashboard)


dashboardPage(skin="black",
  dashboardHeader(title = "Basic dashboard"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
      menuItem("Widgets", tabName = "widgets", icon = icon("th")),
      menuItem(downloadButton('downloadData', label= 'Download', class= "mybutton"))
    ),
       tags$head(tags$style(".mybutton{background-color:red;} .skin-black .sidebar .mybutton{color: green;}") )

    ),
  dashboardBody(
    # Boxes need to be put in a row (or column)
    fluidRow(
      box(plotOutput("plot1", height = 250)),

      box(
        title = "Controls",
        sliderInput("slider", "Number of observations:", 1, 100, 50)
      )
    )
  )
)

服务器.r

function(input, output,session) {
  set.seed(122)
  histdata <- rnorm(500)

  output$plot1 <- renderPlot({
    data <- histdata[seq_len(input$slider)]
    hist(data)
  })

  output$downloadData <- downloadHandler(

    filename = function() { 
      paste("test", '.csv', sep='') 
    },
    content = function(file) {
      write.csv(c(1,2,3,4), file)
    }
  )
}

运行应用程序的代码

library(shiny)
runApp("C://Users/me/PathToProject")

这是返回的内容。你可以看到背景是白色的,但文字是绿色的

enter image description here

最佳答案

即使我也遇到了同样的问题。您可以尝试我在下面提到的代码,这肯定对您有用:

 downloadButton('downloadData', 'Download', class = "butt"),
 tags$head(tags$style(".butt{background-color:#add8e6;} .butt{color: #337ab7;}"))

关于r - 更改下载按钮的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32256366/

相关文章:

r - R 中 ggplot2 yaxis 标签中的 "Squared"上标

从数字矩阵中删除 '%'

r - 如何使用 updateSliderInput 从点更改为范围 slider

R-Shiny 使用 Reactive renderUI 值

r - 如何在 R 中保存有很多点的 pdf

r - 将 mob() 树(partykit 包)与 nls() 模型一起使用

R 中的正则表达式,用于仅在已知单词后查找空格

javascript - Shiny 数据表中的单选按钮,用于一列中的 "subselection"行/分组

javascript - R Shiny 的数据输入自动关闭选项

r - downloadHandler在使用R Shiny下载图像时出错