Get startedGet started for free

More input types

1. More input types

Welcome back.

2. Gapminder plot app

In the next set of exercises, you'll be adding three new inputs, resulting in an app that looks like this. Let's go over each of these new input types.

3. Slider inputs

Slider inputs are another way to let the user select a number. As you can see, they provide more visual feedback than numeric inputs. The user can slide the bar along the slider to choose a number. Similar to numeric inputs, sliders also have a min and a max, but for sliders, these arguments are required. Another big difference between sliders and numeric inputs is that sliders can also be used to select two numbers at once. To do this, the value argument has to be a vector of two numbers rather than a single number. Then the slider will have both a lower and an upper limit, and the return value of that input will be a vector of two numbers.

4. Radio buttons

Radio buttons are a great tool to use when you want to present the user with a few different options and let them pick one. You use the choices argument to populate the list of options. You might notice that unlike all the previous inputs we encountered, radio buttons do not have a value argument for choosing the initial value. Instead, they use the selected argument for the same purpose.

5. Select inputs (dropdowns)

Select inputs are similar to radio buttons. They're also used when you want to give the user a list of options to choose from, and they also have the choices and selected arguments that work in the same fashion as they do in radio buttons. Select inputs are also sometimes called dropdown lists, because of the way they work: in order to choose an option, the user

6. Select inputs (dropdowns)

first clicks on the input field and then

7. Select inputs (dropdowns)

a dropdown listing all the available options appears.

8. Select inputs (dropdowns)

One feature that select inputs have and radio buttons don't is the ability to select multiple options rather than only one. By adding the argument multiple equals TRUE, the user can now select more than one option.

9. Radio buttons vs select inputs

Radio buttons and select inputs can often be used interchangeably because they provide such similar functionality. But it is good to keep a few things in mind when making a decision between the two. Radio buttons are not a great choice when there are many options to choose from, because they can take up a lot of space. On the other hand, with radio buttons the user can see all the options at once, which is not the case for dropdowns. If you want to allow multiple selections, then the choice is clear, you have to use select inputs.

10. Let's practice!

Now you should be ready to add sliders, radio buttons, and dropdowns to your app. Let's go ahead and do that.