Shinyjs: reset to "selected = character(0)" state for radioButtons

Created on 22 Sep 2016  ·  3Comments  ·  Source: daattali/shinyjs

Hey Dean,

thank's for your awesome package. I think it would be useful if the reset() function could reset radioButtons to the state which has no button selected (what you can achieve using selected = character(0).

Most helpful comment

Thanks for letting me know. I'll re-open the issue, but I don't know when/if I'll get around to work on this feature. I would welcome a PR

All 3 comments

I'm sorry but shinyjs will not support that feature until shiny will. What I mean by that is that with shiny you can update the value of a radio button (using updateRadioButtons()), but it doesn't let you select nothing as the value. Also if you look at the documentation for radio buttons, it explicitly says that using character(0) is possible but discouraged for the reason that it's impossible to return to that state. So I prefer to keep within the same framework of shiny, and not provide that functionality.

If you really must do this, you can use a renderUI(radioButtons(...)) if you want :)

@daattali Thanks for this great package! As of 21 days ago this behavior is now properly supported in shiny: https://github.com/rstudio/shiny/commit/770ebc394f1685c2d4a1eb7fd2d1610796281b84 https://github.com/rstudio/shiny/issues/2266
The input value gets reset to NULL.

It would be nice if shinyjs could support this now, Why is this feature useful even if the user can't return to the unselected state?
I am creating a shiny app for (categorical) data input, to avoid accidental, lingering inputs from previous cases/observations I clear all radio boxes, which also disables the submit button (thanks shinyjs 😁 ).

A

library(shiny) # > 1.5.0
library(shinyjs)

  shinyApp(
    ui = fluidPage(
      useShinyjs(),
      div(
        id = "form",
        radioButtons("gender", "Gender", c("Male", "Female"), selected = character(0))
      ),
      actionButton("resetGender", "Reset Gender"),
    ),
    server = function(input, output, session) {

      observeEvent(input$resetGender, {
        updateRadioButtons(session, "gender", selected = character(0))
      })

      observe(print(input$gender))

      })
    }
  )
}

Thanks for letting me know. I'll re-open the issue, but I don't know when/if I'll get around to work on this feature. I would welcome a PR

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gadepallivs picture gadepallivs  ·  6Comments

shosaco picture shosaco  ·  4Comments

abhik1368 picture abhik1368  ·  3Comments

seankross picture seankross  ·  3Comments

Spatial-R picture Spatial-R  ·  3Comments