O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding a dynamic UI

You can create dynamic user interfaces in two different ways: using conditionalPanel or renderUI. We show an example of each in this section.

We use conditionalPanel to show or hide a UI component based on a condition. In this sample, we draw a histogram or scatterplot of mpg based on user selection. For the scatterplot, we fix mpg on the y axis and allow the user to pick a variable for the x axis. Hence, we need to show the list of possible variables for the x axis only when the user chooses the scatterplot option. In ui.R, we check for the condition with input.plotType != 'hist' and then display the list of choices to the user:

 sidebarPanel( selectInput("plotType", "Plot Type", c("Scatter plot" = "scatter", Histogram ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required