Shinydashboard变灰了downloadButton?

时间:2016-03-30 16:38:18

标签: shiny shinydashboard shinyjs

如何修复这个简单示例的下载按钮?

enter image description here

library(shiny)
library(shinydashboard)
library(shinyjs)
header <- dashboardHeader()

sidebar <- dashboardSidebar(shinyjs::useShinyjs(),  
                            actionButton("start_proc", "Click to make download button appear"),
                            p(),
                            downloadButton('data_file', 'Download'))

body <- dashboardBody()

ui <- dashboardPage(header, sidebar, body)


server <- function(input, output) {

  observe({
    if (input$start_proc > 0) {
      Sys.sleep(1)
      # enable the download button
      shinyjs::show("data_file")
    }
  })

  output$data_file <- downloadHandler(
    filename = function() {
      paste('data-', Sys.Date(), '.csv', sep='')
    },
    content = function(file) {
      write.csv(data.frame(x=runif(5), y=rnorm(5)), file)
    }
  )
  # disable the downdload button on page load
  shinyjs::hide("data_file")
}

shinyApp(ui, server)

1 个答案:

答案 0 :(得分:12)

看起来你放在侧边栏内的任何下载按钮看起来都像(与使用hide / show的事实无关)。如果您只是将按钮移动到主体而不是侧边栏,它再次看起来正常,如果您向侧边栏添加更多按钮,它们也会变灰。所以这告诉我们这可能与CSS有关。

如果查看按钮的CSS,您将看到规则

.skin-blue .sidebar a {
    color: #b8c7ce;
}

所以它看起来像某人(无论是闪亮的还是引导程序,我不确定谁负责这个CSS文件)它故意制作链接(而下载按钮实际上只是一个风格不同的链接)灰色文本。所以你可以通过添加自己的CSS来解决这个问题,比如

tags$style(".skin-blue .sidebar a { color: #444; }")
相关问题