Reputation: 193
I want to save user selection as a character vector in my global environment for use in further analysis as input (my_choices
dropdown) How can I save what was selected?
Example:
library("shiny")
library("shinyWidgets")
my_choices <- c(
"2018Q1","2018Q2","2018Q3", "2018Q4", "2019Q1", "2019Q2")
ui <- fluidPage(
pickerInput(
inputId = "id",
label = "SELECT PERIOD:",
choices = my_choices,
selected = NULL,
multiple = TRUE,
options = list(
`actions-box` = TRUE, size = 15, `selected-text-format` = "count > 3"
),
choicesOpt = list(
content = stringr::str_trunc(my_choices, width = 75)
)
),
verbatimTextOutput(outputId = "res")
)
server <- function(input, output, session) {
output$res <- renderPrint(input$id)
}
shinyApp(ui = ui, server = server)
Upvotes: 5
Views: 3453
Reputation: 711
Try global assignment using the double-headed arrow:
observe({
your_global_variable <<- input$id
})
Or using the assign()
function:
observe({
assign(
x = "your_global_variable",
value = input$id,
envir = .GlobalEnv
)
})
Upvotes: 8