Because the checkboxGroup included in Shiny doesn't exactly fit my needs, I am rebuilding the checkboxGroup function. I am looking for a way to include an element named checked
in the arguments passed to tags$input(...) depending on a boolean variable.
I wish that the following code worked as desired, but I understand why it doesn't and shouldn't. Is there any similarly concise syntax I can use to achieve the desired result?
f <- function(selected = TRUE) {
tags$input(
type = 'checkbox',
if(selected) checked = "checked",
"Checkbox Content"
)
}
f()
# actual result:
# <input type="checkbox">
# checked
# Checkbox Content
# </input>
# desired result:
# <input type="checkbox" checked = "checked">
# Checkbox Content
# </input>