0
0
R Programmingprogramming~10 mins

Shiny basics for interactive apps in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a basic Shiny app UI with a title.

R Programming
ui <- fluidPage(
  [1]("My Shiny App")
)
Drag options to blanks, or click blank then click option'
AtitlePanel
BsidebarLayout
CmainPanel
DfluidRow
Attempts:
3 left
💡 Hint
Common Mistakes
Using layout functions like sidebarLayout instead of titlePanel for the title.
Confusing mainPanel with titlePanel.
2fill in blank
medium

Complete the code to define the server function that outputs text.

R Programming
server <- function(input, output) {
  output$text <- renderText({
    [1]("Hello, Shiny!")
  })
}
Drag options to blanks, or click blank then click option'
Aprint
BtextOutput
CrenderText
Dcat
Attempts:
3 left
💡 Hint
Common Mistakes
Using print or cat which do not work as reactive render functions.
Using textOutput which is a UI function, not server.
3fill in blank
hard

Fix the error in the code to correctly display a numeric input in the UI.

R Programming
ui <- fluidPage(
  numericInput([1], "Enter a number:", value = 10)
)
Drag options to blanks, or click blank then click option'
AnumericInput
Bnum
Cinput$num
D"num"
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes around the input ID.
Using input$num which is not valid here.
4fill in blank
hard

Fill both blanks to create a UI with a slider input and display its value as text.

R Programming
ui <- fluidPage(
  sliderInput([1], "Choose a value:", min = 1, max = 100, value = 50),
  textOutput([2])
)
Drag options to blanks, or click blank then click option'
A"slider1"
B"sliderValue"
D"outputText"
Attempts:
3 left
💡 Hint
Common Mistakes
Using different IDs for sliderInput and textOutput.
Not quoting the IDs.
5fill in blank
hard

Fill all three blanks to create a Shiny app that shows the square of a numeric input.

R Programming
ui <- fluidPage(
  numericInput([1], "Number:", value = 2),
  textOutput([2])
)

server <- function(input, output) {
  output[3] <- renderText({
    input$num ^ 2
  })
}

shinyApp(ui, server)
Drag options to blanks, or click blank then click option'
A"num"
B"result"
C$result
D$num
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching IDs between UI and server.
Using incorrect syntax for output assignment.