I’m working through an R Shiny tutorial, and decided to veer off the path, but I’m lost at the moment. A previous exercise had me create a range slider, and I checked the docs to fancy it up with arguments. Now what I’m trying to do is create a textOutput below it to show the value of the difference between the min and max.
library(shiny)
ui <- fluidPage(
sliderInput("rang", "Range", value = c(100, 2000), min = 0, max = 15000,
sep = ",", pre = "$", ticks = FALSE, dragRange = TRUE,
width = "600px"),
textOutput(costDiff())
)
server <- function(input, output, session) {
costDiff <- reactive({
costDiff <- input$rang[2] - input$rang[1]
})
output$costDiff <- renderText("$",{
costDiff()
})
}
shinyApp(ui, server)
I’m receiving:
Error in costDiff() : could not find function "costDiff"
Thanks in advance for your help!
>Solution :
Try this:
library(shiny)
ui <- fluidPage(
sliderInput("rang", "Range", value = c(100, 2000), min = 0, max = 15000,
sep = ",", pre = "$", ticks = FALSE, dragRange = TRUE,
width = "600px"),
textOutput('costDiff')
)
server <- function(input, output, session) {
costDiff <- reactive({
input$rang[2] - input$rang[1]
})
output$costDiff <- renderText({
paste('$', costDiff())
})
}
shinyApp(ui, server)