The code uses data inside plot() but data is not defined anywhere.
Step 2: Understand consequences of missing data
This will cause an error because R cannot find the object data.
Final Answer:
Missing definition of 'data' causes an error -> Option A
Quick Check:
Undefined variable = error [OK]
Hint: Always define variables before using in render functions [OK]
Common Mistakes:
Assuming plot() is invalid in renderPlot
Confusing output variable names
Thinking renderPlotly is required
5. You want to create a Shiny app that shows a histogram of a numeric variable chosen by the user from a dropdown menu. Which approach correctly connects the input and output?
hard
A. Use sliderInput to select variable, then plot histogram of entire data
B. Use numericInput for variable choice, then plot fixed variable in server
C. Use selectInput in UI for variable choice, then in server use renderPlot to plot histogram of data[[input$var]]
D. Use textInput for variable name, then plot histogram of input$var directly
Solution
Step 1: Choose correct input control for variable selection
selectInput lets user pick a variable name from choices.
Step 2: Use input to select data column in server
Access the chosen variable as data[[input$var]] and plot histogram with renderPlot.
Final Answer:
Use selectInput in UI for variable choice, then in server use renderPlot to plot histogram of data[[input$var]] -> Option C
Quick Check:
Dropdown input + dynamic plot = Use selectInput in UI for variable choice, then in server use renderPlot to plot histogram of data[[input$var]] [OK]
Hint: Use selectInput for choices, access with data[[input$var]] [OK]
Common Mistakes:
Using numericInput instead of selectInput
Trying to plot input$var directly without data
Using sliderInput for variable selection
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.