Get startedGet started for free

Inputs

1. Inputs

Let's learn about the other kinds of inputs available for you to use in your Shiny apps.

2. Example inputs

So far in the course, we've used textInput, which allowed users to input text that was utilized in the server to update the graph. Shiny makes available a wide variety of other kinds of inputs as well. For example, you can use a sliderInput to allow users to select a year. A selectInput is a great way to allow for a selection from a list of fixed options, such as a preference for dogs or cats. The numericalInput allows you to provide a range of numbers users can choose from, which they can increase or decrease using the little arrows. A dateRangeInput allows you to provide users with a set of dates, and a calendar drop down appears when they click so they can select a specific one. These are just four examples, and Shiny definitely provides more. When designing your app, depending on the kind of controls you want to grant your users, be sure to choose the inputs appropriately.

3. Input functions

All input functions have their first argument, an inputId, in common. The inputId needs to be a character string, and each input should have a unique id so you can refer to it in the server to make updates to the app. Many inputs have a label as their next argument, which is a character string that is often shown to the user to let them know what they should do with the input. From there, each input function has unique arguments that help you successfully build the app. A selectInput requires a list of choices. The user will automatically see the first choice in the list. A sliderInput requires value that the slider will be set at by default, then a min and max of the other values users can choose from. Remember that, if at any time, you want to see the arguments to a Shiny input function, you can use the built-in R help by putting a question mark in front of a function name or by putting the name inside the help function.

4. Where to use inputs

Finally, you'll always use input functions in the UI of your app. This app uses textInput and a selectInput. In the server, you can always refer to your input using input $ inputId. This is why you need your ids to be unique. Otherwise, you can't refer to them down in the server and use them to update the app appropriately.

5. Let's practice!

Now that we've discussed different Shiny inputs and talked about how to use them, let's practice.