Return integer values ​​from RadioButton in Shiny

I created some switches in Shiny; However, I am wondering if there is a way to return the return value an integer, not a character.

The desire for integers appeared in the context of RadioButton used to select gender.

When I do this:

radioButtons(inputId="gender", "Gender", choices = list("combined" = 0, "male" = 1, "female" = 2) 

I find that

 print(str((input$gender))) 

gives me

 chr "0" 

I know I can change this on the server:

 gender <- as.integer(input$gender) 

but I try to clear this code by cutting down the lines.

Is it possible to change the type of output in the user interface?

+5
source share
1 answer

The radioButtons() function argument selection documentation says, "Values ​​must be strings; other types (such as logic and numbers) will be forced to strings. 'If you use the choiceNames and choiceValues instead of choices , normalizeChoicesArgs() inside radioButtons() again will force values ​​to the character (this is true for other inputs like checkboxGroupInput() ).

Since you define a list in choices that will always return either "0" , "1" , or "2" , you can safely force values ​​to a numeric data type in a brilliant application server function.

+1
source

Source: https://habr.com/ru/post/1209973/


All Articles