Shinyjs does not disable downloadButton when referencing a div-id

I want to disable multiple buttons that are placed together in a div(id = "buttons",...), where some of the buttons are ashiny::downloadButton().

I disable the buttons using shinyjs::disable(). ( In the real case they are disabled using a condition with toggleState but the problem stays the same using a simple disable).

Consider the following small example below:

library(shiny)
library(shinyjs)

ui <- fluidPage(
    useShinyjs(),
    div(id = "buttons",
        actionButton("ActionButton", label = "ActionButton"),
        downloadButton("DownloadButton", label = "DownloadButton")
        )
    )
    
server <- function(input,output){
  observe({
        shinyjs::disable("buttons")
      })
}

shinyApp(ui,server)

The problem

The download button does not get disabled in the above example. It does get disabled when I explicitly add shinyjs::disable("DownloadButton"). But even then the CSS behaves differently, namely I get a "forbidden" symbol when hovering the actionButton but not the download button.

How do I get the download button to behave the same as the action Button?

Extra Info

Shiny version: 1.5.0
Shinyjs version: 2.0.0
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit) ( But the same happens also on a windows machine)
Running under: Ubuntu 20.04.1 LTS

I don't think this is an error, its more that shinyjs doesn't offer what you want as a feature out of the box. inputs can be disabled, but div's are not inputs, and also theres no implementation supporting shinyjs disable to crawl through a divs members looking for disableable elements. Probably the easiest solution, is to do some minimal 'bookkeeping' for yourself, to make a simple object to record which disableable buttons belong to a group that you want to deal with together and then use purrr to iterate . like this.

library(shiny)
library(shinyjs)
library(purrr)


ui <- fluidPage(
  useShinyjs(),
  div(id="btns",
      actionButton("ActionButton", label = "ActionButton"),
      downloadButton("DownloadButton", label = "DownloadButton")
  )
)

server <- function(input,output){
  btns_list <- list("ActionButton",
                    "DownloadButton")
  purrr::walk(
    btns_list,
    shinyjs::disable
  )}

shinyApp(ui,server)

I do have the feeling that shinyjs is able to "crawl" through the div members, since it is able to find all the actionButton's. And not only buttons for that matter, all different kinds of shiny inputs, except for the downloadButton.

Below is again an example with many nested div's where shinyjs is able to find the actionButton and selectInput and disables them. But again not the download button.

library(shiny)
library(shinyjs)

ui <- fluidPage(
    useShinyjs(),
    div(id = "inputs",
        div(id = "nested_div",
            actionButton("ActionButton", label = "ActionButton")
        ) ,
        downloadButton("DownloadButton", label = "DownloadButton"),
        div(id = "nested_div2",
            div(id = "nested_nested_div",
                selectInput("selectInput", label = "selectInput",c("A"))
            )
        )
    )
)

server <- function(input,output){
  observe({
        shinyjs::disable("inputs")
      })
}

shinyApp(ui,server)
1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.