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

click() doesn't work with download buttons #198

Closed
daattali opened this issue Jan 4, 2020 · 5 comments
Closed

click() doesn't work with download buttons #198

daattali opened this issue Jan 4, 2020 · 5 comments

Comments

@daattali
Copy link
Owner

daattali commented Jan 4, 2020

click() works with regular buttons but not with download buttons.

Example:

library(shiny)

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

server <- function(input, output, session) {
  observe({
    shinyjs::click("go")
  })
  output$go <- downloadHandler(
    filename = "file",
    content = function(file) {
      print("test")
    }
  )
}

shinyApp(ui, server)
@daattali
Copy link
Owner Author

daattali commented Jan 4, 2020

Fixed with cc9678c

@daattali daattali closed this as completed Jan 4, 2020
@stevepowell99
Copy link

is there any way to make click() work with selectors rather than ids? I have an element which I would like to click on but it doesn't have an id.

@federiva
Copy link

Maybe you can try something like?:

runjs("$(<'yourselector'>).click()")

Just try to be sure that you're not running that on multiple elements, just to avoid unexpected click events somewhere else in the DOM

@daattali
Copy link
Owner Author

The function is meant to be used for action buttons, which always have IDs, and it's kind of a strange thought to click on multiple buttons simultaneously. Therefore it can only be used with an ID. You can use the suggestion above to make your own version of click with some minimal javascript.

@stevepowell99
Copy link

tx, this works. The use case is sorting a DT datatable by a specific column, where there are no IDs but I can identify the correct column with a selector, and DT doesn't provide easy sorting via proxy, so this is really useful.

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