I am trying to make an app that would take product ID from input field and then download data from server and use that data to create a selectInput. My UI part:
ui <- fluidPage(
titlePanel("Alternatives"),
sidebarLayout(
sidebarPanel(
textInput("text1",
label = h3("Enter product ID:"),
value = "ID"),
actionButton('run', 'Run'),
hr(),
selectInput("selectinput",
label = "Alternatives:",
choices = choices_for_input
)
),
mainPanel(
)
)
My server part:
server <- function(input, output, session) {
observeEvent(input$run, {
alldata <- data_request(as.numeric(input$text1)) #getting data from server
})
### putting data into correspoding datatables
fields <- as.data.table(do.call(rbind, alldata$fields))
setnames(fields,
c("V1", "V2", "V3", "V4", "V5"),
c('prod_id', 'field', 'item1', 'alternative', 'score'))
scores <- as.data.table(do.call(rbind, alldata$scores))
setnames(scores,
c("V1", "V2"),
c("prod_id", "score"))
### list for selectInput choices
choices_for_input <- scores$prod_id
}
but I get an error:
object 'choices_for_input' not found
I could use some default value like NO VALUES inside my choices to begin with and later update the choice list, but I want the selectInput only appear after all the data is prepared with all the right selections. But I am not sure how...