I am trying to return a character vector created in a reactive expression in Shiny. However, when I run the app, I get the following:
Error: could not find function "check_case"
check_case
is a reactive expression, not a function.
I can see a number of questions from people with similar issues, but the answers don't seem to fit this (for e.g., missing parentheses when calling reactive expression; calling something that hasn't been returned in the reactive expression).
I've tried immediately translating check_case()
into a character vector in the output before using paste
. I have also tried adding more arguments to paste
so it includes sep =
and collapse =
, in case this is part of the issue, but this doesn't change the result I'm getting.
I currently have two theories:
- There is an issue in the way I am using a reactive expression to return a character vector. Normally I use them to return dataframes so there might be something I'm missing here.
- There is an issue in the way I am using
paste
to refer to a character vector.
Code:
library(shiny)
library(shinydashboard)
sidebar <- dashboardSidebar(
selectInput(
"case_select", label = "Select case",
choices = c("Upper", "Lower")
)
)
body <- dashboardBody(
fluidRow(
htmlOutput("text"))
)
ui <- dashboardPage(dashboardHeader(title = "Example"),
sidebar,
body
)
server <- function(input, output) {
output$check_case <- reactive({
if (input$case_select == "Upper") {
case_list <- c("A", "B", "C")
} else {
case_list <- c("a", "b", "c")
}
return(case_list)
})
output$text <- renderUI({
check_case <- check_case()
HTML(paste(check_case, sep = "", collapse = ""))
})
}