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
Allow arbitrary UI code in the choices for radio buttons and checkbox group input #1521
Merged
Merged
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
00276ab
working but ugly
bborgesr 2c44437
handle dependencies
bborgesr 9571285
better
bborgesr 4ea3990
added documentation and example
bborgesr cc67907
uncommenting
bborgesr b6bbd11
fix tests
bborgesr 35136b9
update funs
bborgesr f982be2
fix docs
bborgesr 4055c6b
make checkChoicesArgs fun
bborgesr e909e35
name elements of return list
bborgesr f14dd69
minor updates
bborgesr c6e1e40
don't propagate `choices` beyond normalizeCheckArgs() (only keep `cho…
bborgesr 2b28ea2
replace `choicesNames` with `choiceNames`, and `choicesValues` with `…
bborgesr 81fe6a1
a bunch of tests
bborgesr 8961778
news item and comment
bborgesr bcd8fce
some changes after feedback from Winston
bborgesr 362ff9f
try to adapt things for selectInput
bborgesr 2488690
add mustExist to update-input
bborgesr 0687f04
revert selectInput adaptation (and add a space in error message)
bborgesr e1a2752
added breaking change NEWS item
bborgesr 724fa36
edge cases and numbers
bborgesr c0902f8
remove call to validateselected
bborgesr File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -452,16 +452,18 @@ updateSliderInput <- function(session, inputId, label = NULL, value = NULL, | |
|
||
|
||
updateInputOptions <- function(session, inputId, label = NULL, choices = NULL, | ||
selected = NULL, inline = FALSE, | ||
type = 'checkbox') { | ||
if (!is.null(choices)) | ||
choices <- choicesWithNames(choices) | ||
if (!is.null(selected)) | ||
selected <- validateSelected(selected, choices, session$ns(inputId)) | ||
selected = NULL, inline = FALSE, type = NULL, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to error if |
||
choiceNames = NULL, choiceValues = NULL) { | ||
if (is.null(type)) stop("Please specify the type ('checkbox' or 'radio')") | ||
|
||
args <- normalizeChoicesArgs(choices, choiceNames, choiceValues, mustExist = FALSE) | ||
|
||
if (!is.null(selected)) selected <- as.character(selected) | ||
|
||
options <- if (!is.null(choices)) { | ||
options <- if (!is.null(args$choiceValues)) { | ||
format(tagList( | ||
generateOptions(session$ns(inputId), choices, selected, inline, type = type) | ||
generateOptions(session$ns(inputId), selected, inline, type, | ||
args$choiceNames, args$choiceValues) | ||
)) | ||
} | ||
|
||
|
@@ -510,9 +512,10 @@ updateInputOptions <- function(session, inputId, label = NULL, choices = NULL, | |
#' } | ||
#' @export | ||
updateCheckboxGroupInput <- function(session, inputId, label = NULL, | ||
choices = NULL, selected = NULL, | ||
inline = FALSE) { | ||
updateInputOptions(session, inputId, label, choices, selected, inline) | ||
choices = NULL, selected = NULL, inline = FALSE, | ||
choiceNames = NULL, choiceValues = NULL) { | ||
updateInputOptions(session, inputId, label, choices, selected, | ||
inline, "checkbox", choiceNames, choiceValues) | ||
} | ||
|
||
|
||
|
@@ -552,10 +555,15 @@ updateCheckboxGroupInput <- function(session, inputId, label = NULL, | |
#' } | ||
#' @export | ||
updateRadioButtons <- function(session, inputId, label = NULL, choices = NULL, | ||
selected = NULL, inline = FALSE) { | ||
selected = NULL, inline = FALSE, | ||
choiceNames = NULL, choiceValues = NULL) { | ||
# you must select at least one radio button | ||
if (is.null(selected) && !is.null(choices)) selected <- choices[[1]] | ||
updateInputOptions(session, inputId, label, choices, selected, inline, type = 'radio') | ||
if (is.null(selected)) { | ||
if (!is.null(choices)) selected <- choices[[1]] | ||
else if (!is.null(choiceValues)) selected <- choiceValues[[1]] | ||
} | ||
updateInputOptions(session, inputId, label, choices, selected, | ||
inline, 'radio', choiceNames, choiceValues) | ||
} | ||
|
||
|
||
|
@@ -601,8 +609,7 @@ updateRadioButtons <- function(session, inputId, label = NULL, choices = NULL, | |
updateSelectInput <- function(session, inputId, label = NULL, choices = NULL, | ||
selected = NULL) { | ||
choices <- if (!is.null(choices)) choicesWithNames(choices) | ||
if (!is.null(selected)) | ||
selected <- validateSelected(selected, choices, inputId) | ||
if (!is.null(selected)) selected <- as.character(selected) | ||
options <- if (!is.null(choices)) selectOptions(choices, selected) | ||
message <- dropNulls(list(label = label, options = options, value = selected)) | ||
session$sendInputMessage(inputId, message) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It would be more accurate to say that it had been deprecated (not soft-deprecated) since 0.10.0.