Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabled (via shinyjs) actionButton and downloadButton behave differently #132

Closed
GiCollini opened this issue Jun 20, 2017 · 5 comments
Closed

Comments

@GiCollini
Copy link

Hi,

I noticed that the cursor over disabled (via shinyjs) actionButton changes (form classic cursor to barred cyrcle) while over disabled (via shinyjs) downloadbutton does not change.

Below a minimal example

require(shiny)
require(shinyjs)

#### initialize ####
rm(list=ls())

#### Global ####

test_df <- data.frame(LETTERS = letters, NUMBERS = 1:length(letters), stringsAsFactors = F)

#### Server ####
server <- function(input, output){
  
  #### Initialize Values ####
  
  values <- reactiveValues()
  
  values$show <- TRUE
  values$counter <- 1
  
  observeEvent(input$update,{
    values$counter <- if_else((values$counter + 1) %% (length(letters) +1) > 0, (values$counter + 1) %% (length(letters) +1), 1)
  })
  
  observeEvent(input$hide_show_button,{
    values$show <- (values$show + 1) %% 2
  })
  
  #### Download ####
  
  output$downloaddata <- downloadHandler(
    filename = function() {paste0("OUTPUT_",format(Sys.time(), format="%Y%m%d%H%M%S"),".csv")},
    content = function(file) {
      write.csv2(test_df[values$counter,], file, row.names = F)
    }
  )
  
  #### Disable/Enable ####
  
  observe({
    if(values$show == TRUE){
      shinyjs::enable("update")
      shinyjs::enable("downloaddata")
    }else{
      shinyjs::disable("update")
      shinyjs::disable("downloaddata")
    }
  })
  
  #### Output ####
  
  
  output$check <- renderPrint({
    test_df[values$counter,]
  })
  
  #### END SERVER ####
  
  }



#### UI ####
ui <- fluidPage(
  useShinyjs(),
  fluidRow(
    column(
      width = 6,
      div(id = "buttons_wrapper",
          style = "margin: 5%;
          padding: 5%;",
          div(id = "buttons_wrapper_update",
              style = "display: block;
              margin: 5%;
              padding: 5%;",
            actionButton(inputId = "update",
                         label = "Update",
                         icon = icon("refresh")
            )
        ),
        div(id = "buttons_wrapper_hide_show",
            style = "display: block;
            margin: 5%;
            padding: 5%;",
            actionButton(inputId = "hide_show_button",
                         label = "Hide/Show",
                         icon = icon("eye-slash")
            )
        ),
        div(id = "buttons_wrapper_download",
            style = "display: block;
            margin: 5%;
            padding: 5%;",
            downloadButton(outputId = "downloaddata",
                           label = "Download"
            )
        )
        )
    ),
    column(
      width = 6,
      verbatimTextOutput("check")
    )
  )
)

#### Run ####
shinyApp(ui = ui, server = server)
@daattali
Copy link
Owner

You're right that download buttons do not change the cursor when you hover over their disabled state.

However, this is not a shinyjs issue - shinyjs is responsible for making the button disabled (which it is), and the CSS to change the cursor is done by bootstrap or shiny. It would be out of scope of shinyjs to add CSS for this.

@GeiserX
Copy link

GeiserX commented Feb 26, 2019

Hi there.

Simply a disabled(downloadBttn("download")) will only disable the perimeter of the button, not the inside of it. Is there anything I can do? The button even actually works when pressed.

Thank you

@daattali
Copy link
Owner

A download button should not (and to my knowledge does not) work when disabled. If you think there is a bug, please submit a minimal reproducible code sample.

@daattali
Copy link
Owner

library(shiny)

ui <- fluidPage(
  shinyjs::useShinyjs(),
  shinyjs::disabled(downloadButton("test", "test"))
)

server <- function(input, output, session) {
  output$test <- downloadHandler(
    filename = "test.csv",
    content = function(con) {
      write.csv(mtcars, con)
    }
  )
}

shinyApp(ui, server)

The button does not work

@GeiserX
Copy link

GeiserX commented Mar 18, 2019

Sorry for the delay.

Try this example:

library(shiny)
library(shinyjs)
library(shinyWidgets)

ui <- fluidPage(
  useShinyjs(),
  disabled(downloadBttn(outputId = "downloadCSV", label = "Download CSV", size = "sm"))
)

server <- function(input, output, session) {
  output$test <- downloadHandler(
    filename = "test.csv",
    content = function(con) {
      write.csv(mtcars, con)
    }
  )
}

shinyApp(ui, server)

In your example you used the usual downloadButton but I am using the shinyWidgets' downloadBttn.

I can successfuly download the mtcars dataframe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants