I am trying to pass reactive data to updateSelectizeInput but instead get the following error :
Error in .getReactiveEnvironment()$currentContext() : Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
My code is as follows :
ui.R
library(shiny) ui_panel <- tabPanel("Text Input Test", sidebarLayout( sidebarPanel( selectizeInput('Organisations', label = "Organisation Search", choices = NULL, options = list( placeholder = 'Type the organisation name', maxOptions = 10, maxItems = 1, searchConjunction = 'and')), tags$style(type="text/css",".selectize-input::after{visibility:hidden;};" ), br(), selectInput( inputId="selectData", label="", choices=c("Universities", "Hospitals") ), br() ), mainPanel( tabsetPanel( tabPanel("output of Organisation search details",htmlOutput("orgsearchdetails")) ) ) ))ui <- shinyUI(navbarPage("",ui_panel))
server.R
library(shiny) shinyServer( function(input, output, session) { orgdata <- reactive({if(input$selectData=='Universities'){ orgdata <- read.csv("universities.csv") }else if (input$selectData=='Hospitals'){ orgdata <- read.csv("hospitals.csv") } orgdata }) updateSelectizeInput(session, 'Organisations', choices = as.character(unique( orgdata()$name)), server = TRUE) output$orgsearchdetails <-renderUI({ }) session$onSessionEnded(function() { dbDisconnect(con) }) })
Is there a way I can pass the reactivity of the selectInput to the updateSelectizeInput ?
I am opting for updateSelectizeInput instead of a reactive selectInput so as to avoid populating the filed at the launch of the application.
Any help or insight is highly welcome. thank you in advance.