I want to pass distinct labels to selectizeInput in Shiny. I then want the user input from selectize to pass an encoded parameter value to a function. I have the parameter codes and labels stored in a data frame. So, I should be able to access the parameter field in the data frame using a logical matching statement on the labels. However, I only seem to get the row number as output - not the actual parameter code. Also, multiple selections are not displaying.
Please see example below:
library(shiny)
library(dplyr)
dropdown_A<-as.data.frame( cbind(labels = c("red", "white", "blue"), parameter = c(800, 72, 9048)))
dropdown_B<-as.data.frame( cbind(labels = c("green", "purple", "orange"), parameter = c("xyz","def","abc")))
shinyApp(
ui = fluidPage(
fluidRow(
wellPanel(
selectizeInput("A", label = p("Select a color"), choices = as.character(dropdown_A$labels), multiple = TRUE),
selectizeInput("B", label = p("Select another color"), choices = as.character(dropdown_B$labels), multiple = TRUE))),
fluidRow(verbatimTextOutput("Value_A")),
fluidRow(verbatimTextOutput("Value_B"))),
server = function(input, output, session){
A<-reactive({
if (is.null(input$A))
return ("Please select a color")
else (dropdown_A %>% filter(labels == input$A)%>% select(parameter))
})
B<-reactive({
if (is.null(input$B))
return ("Please select another color")
else (dropdown_B %>% filter(labels == input$B)%>% select(parameter))
})
output$Value_A<-renderText({
as.character(A())
})
output$Value_B<-renderText({
as.character(B())
})
}
)
Is it that what you want? Best Sigbert
library(shiny)
choices_A <- as.list(c(800, 72, 9048)); names(choices_A) <- c("red", "white", "blue")
choices_B <- as.list(c("xyz","def","abc")); names(choices_B) <- c("green", "purple", "orange")
shinyApp(
ui = fluidPage(
fluidRow(
wellPanel(
selectizeInput("A", label = p("Select a color"), choices = choices_A, multiple = TRUE),
selectizeInput("B", label = p("Select another color"), choices = choices_B, multiple = TRUE))),
fluidRow(verbatimTextOutput("Value_A")),
fluidRow(verbatimTextOutput("Value_B"))),
server = function(input, output, session){
A<-reactive({
if (is.null(input$A))
return ("Please select a color")
else input$A
})
B<-reactive({
if (is.null(input$B))
return ("Please select another color")
else input$B
})
output$Value_A<-renderText({