-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Copied the logic from radioButton to updateRadioButton #3066
Conversation
this will close #3064
|
||
# length of selected can't be more than one | ||
if (length(selected) > 1) | ||
stop("The 'selected' argument must be of length 1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the other PR, this will be "length 0 or 1." We might as well add that text now.
Also, this should be warning()
instead of stop()
. This is because this function will typically be called from an observer, and if there's a stop()
in an observer, it will stop the entire application -- and that could stop it for multiple users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the logic implemented in the other PR, length 0 will be authorized: it will set all buttons to unselected, so I'm not sure about changing the test/text?
My choice for a stop()
was that if you do updateRadioButtons(session, "radio", selected = letters[5:10])
for example, nothing is happening.
pkgload::load_all()
ui <- fluidPage(
radioButtons("radio", "Radios", letters),
actionButton("change", "Change")
)
server <- function(input, output, session) {
observeEvent(input$change, {
# This part doesn't do anything
updateRadioButtons(session, "radio", selected = letters[5:10])
})
}
shinyApp(ui, server)
Error in the JS console:
shiny.min.js:3 Uncaught TypeError: t.replace is not a function
at exports.$escape (shiny.min.js:3)
at exports.InputBinding.setValue (shiny.min.js:3)
at exports.InputBinding.receiveMessage (shiny.min.js:3)
at ShinyApp.<anonymous> (shiny.min.js:3)
at ShinyApp._sendMessagesToHandlers (shiny.min.js:3)
at ShinyApp.dispatchMessage (shiny.min.js:3)
at WebSocket.n.onmessage (shiny.min.js:3)
Maybe another logic then would be to take the last element of selected
then? This would match the behavior of updateSelectInput
:
ui <- fluidPage(
selectInput("select", "Select", letters),
actionButton("change", "Change")
)
server <- function(input, output, session) {
observeEvent(input$change, {
# This will make select be 'j', the last element of `letters[5:10]`
updateSelectInput(session, "select", selected = letters[5:10])
})
}
shinyApp(ui, server)
Or the first, then matching the behavior of updateSliderInput
ui <- fluidPage(
sliderInput("slider", "slider", 1, 10, 4),
actionButton("change", "Change")
)
server <- function(input, output, session) {
observeEvent(input$change, {
# This will make slider be 1
updateSliderInput(session, "slider", value = 1:3)
})
}
shinyApp(ui, server)
Which raises another question: shouldn't both behave the same way (i.e either taking the first or the last)?
@schloerke any reason for closing this PR? |
@ColinFay I can not manually change the base merge branch. 😞 Do you mind resubmitting the PR? Sorry for the hassle |
this will close #3064