Does anyone have a way to determine the type of widget from its name/ID? For example if "my_text"
is a textInput
widget, then I would like to be able to call:
is.textInput("my_text")
and be returned TRUE
. Or to call
widget.type("my_list")
and be returned "textInput"
. But neither of these functions exist.
I have looked through all the functions in the shiny
and shinyWidgets
packages and don't see anything to this extent. There are some back-end functions like session$sendInputMessage()
that are not intended for users but might assist.
My naive solution is to try something like the following (sorry if my tryCatch()
syntax is not quite right, I don't use it very often):
is.textInput <- function(widget_id){
out <- tryCatch(
{
# attempt to treat it as a textInput, change it and change it back
tmp <- input[[widget_id]]
updateTextInput(session, widget_id, value = character(0))
updateTextInput(session, widget_id, value = tmp)
},
error=function(cond) { return("NO") },
warning=function(cond) { return("NO") },
finally={}
)
# if error message happens then not textInput
if(out == "NO")
return("FALSE")
# if no error message then is textInput
return("TRUE")
}
But I would rather not be creating deliberate errors/exceptions. And I do not want a logical check to be making changes to the state of the app.
Other suggests for how I might accomplish this?