daattali / shinyjs

💡 Easily improve the user experience of your Shiny apps in seconds
https://deanattali.com/shinyjs
Other
734 stars 119 forks source link

Reset Radiobuttons with selected = character(0) #220

Closed assignUser closed 2 years ago

assignUser commented 3 years ago

Fixes #85 I have tested the changes on the example code and in my own app, everything looks fine.

daattali commented 3 years ago

This does not work for me.

library(shiny)

ui <- fluidPage(
  shinyjs::useShinyjs(),
  radioButtons("test", "test", c("a","b"), selected=character(0)),
  actionButton("reset","reset")
)

server <- function(input, output, session) {
  observeEvent(input$reset, {
    shinyjs::reset("test")
  })
}

shinyApp(ui, server)

The reset button does not reset the radio button. Does this code work for you?

assignUser commented 3 years ago

Yes: reset You are using shinyjs:: did you do devtools::install() before? If so maybe you need to reload shinyjs/restart the session?

daattali commented 3 years ago

That's a good question, but yes I am using the version that I modified. The only thing is maybe our shiny versions aren't the same? I'm on 1.5.0

daattali commented 3 years ago

I actually get a javascript error when I try to reset to selected(0) now (I don't get the error when resetting to a value, or before this modification)

image

I got the error on both chrome and firefox.

Do you have access to another machine , perhaps a cloud server, where you can test and see if you also get my issue?

daattali commented 3 years ago

Oh I think the issue is that I'musing the CRAN version of shiny, and this essentially calls shiny's function for updating radio buttons which didn't work until the new dev version, which I don't have.

I don't want to cause javascript errors in the console that didn't exist before, that for me would be an unacceptable regression. So how about we check for the shiny version and only add your code is shiny is new enough?

assignUser commented 3 years ago

Ah yes that makes sense. I added a check for that.

daattali commented 3 years ago

Thanks! I'll wait until the new shiny version is in CRAN and then merge

daattali commented 2 years ago

A little late, but I finally remembered to add this in! Tested and works , thanks