0
0
R Programmingprogramming~20 mins

Shiny basics for interactive apps in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Shiny Interactive Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Shiny app's text output?

Consider this Shiny app code snippet. What will be displayed in the app's main panel when the slider is moved to 5?

R Programming
library(shiny)

ui <- fluidPage(
  sliderInput("num", "Choose a number", min = 1, max = 10, value = 1),
  textOutput("result")
)

server <- function(input, output) {
  output$result <- renderText({
    paste("You selected", input$num * 2)
  })
}

shinyApp(ui, server)
AYou selected NULL
BYou selected 1
CYou selected 5
DYou selected 10
Attempts:
2 left
💡 Hint

Remember the slider value is multiplied by 2 before displaying.

🧠 Conceptual
intermediate
1:30remaining
Which reactive function updates automatically when input changes?

In Shiny, which function is used to create a reactive expression that updates automatically when its inputs change?

AobserveEvent()
BrenderUI()
Creactive()
Disolate()
Attempts:
2 left
💡 Hint

Think about a function that returns a value and updates reactively.

🔧 Debug
advanced
2:30remaining
Why does this Shiny app not update the plot when slider changes?

Look at this server code snippet. The plot does not update when the slider input changes. What is the cause?

R Programming
server <- function(input, output) {
  output$plot <- renderPlot({
    x <- 1:10
    y <- x * 2
    plot(x, y)
  })
}
AThe plot does not use input$num, so it never reacts to slider changes.
BrenderPlot() is missing parentheses after it.
CThe plot function is incorrect and causes an error.
DThe server function is missing a return statement.
Attempts:
2 left
💡 Hint

Check if the reactive input is used inside renderPlot.

📝 Syntax
advanced
2:00remaining
Which option causes a syntax error in Shiny UI definition?

Which of these UI code snippets will cause a syntax error?

A
fluidPage(
  titlePanel("App Title"),
  sidebarLayout(
    sidebarPanel(
      sliderInput("num", "Number", 1, 10, 5),
    ),
    mainPanel(
      textOutput("text")
    )
  )
)
B
)
)  
)    
)"txet"(tuptuOtxet      
(lenaPniam    
,)    
)5 ,01 ,1 ,"rebmuN" ,"mun"(tupnIredils      
(lenaPrabedis    
(tuoyaLrabedis  
,)"eltiT ppA"(lenaPeltit  
(egaPdiulf
C
luidPage(
  titlePanel("App Title"),
  sidebarLayout(
    sidebarPanel(
      sliderInput("num", "Number", 1, 10, 5)
    ),
    mainPanel(
      textOutput("text")
    )
  )
)
D
fluidPage(
  titlePanel("App Title"),
  sidebarLayout(
    sidebarPanel(
      sliderInput("num", "Number", 1, 10, 5)
    ),
    mainPanel(
      textOutput("text")
    )
  )
)
Attempts:
2 left
💡 Hint

Look for misplaced commas inside function calls.

🚀 Application
expert
3:00remaining
How many items are in the reactiveValues list after this code runs?

Given this server code, how many items does vals contain after the app starts?

R Programming
server <- function(input, output, session) {
  vals <- reactiveValues()
  vals$a <- 10
  vals$b <- 20
  observe({
    vals$c <- vals$a + vals$b
  })
}
A2
B3
C1
D0
Attempts:
2 left
💡 Hint

Consider when the observe block runs and what it adds to vals.