【问题标题】:Change the background color of the downloadButton更改下载按钮的背景颜色
【发布时间】:2015-11-22 05:57:54
【问题描述】:

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

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

ui.r

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

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

【问题讨论】:

  • downloadButtonclass 参数可以满足您的需求。当然,您必须创建一个 css 类来链接该函数的 class 参数。

标签: r shiny


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-04
    • 1970-01-01
    • 2023-04-01
    • 2021-06-22
    • 2015-04-03
    相关资源
    最近更新 更多