3 Basic reactivity
3.3.6 Exercises
Server 1
-
input$greeting
–>output$greeting
- Inside
renderText
,name
–>input$name
- Fixed code:
server1 <- function(input, output, server) {
output$greeting <- renderText(paste0("Hello ", input$name))
}
Server 2
- Make
greeting
a reactive:greeting <- reactive(paste0("Hello ", input$name))
- Since
greeting
is now a reactive, add parenthesis around it:output$greeting <- renderText(greeting())
- Fixed code:
server2 <- function(input, output, server) {
greeting <- reactive(paste0("Hello ", input$name))
output$greeting <- renderText(greeting())
}
Server 3
- Spelling error:
output$greting
–>output$greeting
- Missing
renderText()
- Fixed code:
server3 <- function(input, output, server) {
output$greeting <- renderText(paste0("Hello ", input$name))
}
- Solution at Mastering Shiny Solutions 2021
- When you use
range()
orvar()
, other readers won’t know if you are using a reactive or the built-in R function.
Not sure why code fails, but maybe reading the chapter on Tidy evaluation will help.