Shiny Application Layouts Exercises (Part-7)

[This article was first published on R-exercises, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Shiny Application Layouts – Conditional Panel

In the seventh part of our series we will use the rnorm() function to create a UI with a Conditional Panel.

This type of Panel is visible only when the value of a JavaScript expression is true. The JS expression is re-evaluated every time shiny runs with a different input.

This part can be useful for you in two ways.

First of all, you can see different ways to enhance the appearance and the utility of your shiny app.

Secondly you can make a revision on what you learnt in “Building Shiny App” series as we will build basic shiny staff in order to present it in the proper way.

Read the examples below to understand the logic of what we are going to do and then test yous skills with the exercise set we prepared for you. Lets begin!

Answers to the exercises are available here.

Exercise 1

Create the initial fluid page. HINT: Use fluidPage().

Exercise 2

Name your application with a title. ΗΙΝΤ: Use titlePanel().

Exercise 3

Create 3 columns as space for your slider. HINT: Use column().

Exercise 4

Inside the column() you just created place a well Panel. HINT: Use wellPanel().

Learn more about Shiny in the online course R Shiny Interactive Web Apps – Next Level Data Visualization. In this course you will learn how to create advanced Shiny web apps; embed video, pdfs and images; add focus and zooming tools; and many other functionalities (30 lectures, 3hrs.).

Exercise 5

In the well Panel you just created put a slider with features min = 10, max = 200, value = 40 and step = 10. HINT: Use sliderInput().

Now we are going to create the message that will explain why the plot will not be displayed when the JS expression is NOT TRUE.

Exercise 6

Use 5 columns as space for your message and the plot we are going to create later. The message will be “Less than 40-Error”.

Conditional Panel

The condition of the Conditional Panel is a JavaScript expression. Input values like input$n are accessed with dots, as in input.n
#ui.R
conditionalPanel("input.n >= 50")

Exercise 7

In the columns you just created place a conditional panel with condition the number of the input “c” to be more than 40 in order to display the plot.

Exercise 8

Create the ui side of your plot. HINT: Use plotOutput().

This is the server side of the scatter plot you want to create.
#server.R
output$sc <- renderPlot({ x <- rnorm(input$c) y <- rnorm(input$c) plot(x, y) })

Exercise 9

Create the server side of your plot. HINT: Use renderPlot().

Exercise 10

Change your condition to <=40 and spot the differnece.

To leave a comment for the author, please follow the link and comment on their blog: R-exercises.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)