将用户输入(发光的应用程序)保存到R中的全局变量

时间:2018-09-24 08:39:08

标签: r shiny

我想在全局环境中将用户选择另存为字符向量,以用作进一步的分析作为输入(my_choices下拉列表)如何保存选择的内容?

用户Victorp提供的示例。非常感谢

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)

1 个答案:

答案 0 :(得分:1)

尝试使用双向箭头进行全局分配:

observe({
   your_global_variable <<- input$id
})

或使用assign()函数:

observe({
   assign(
      x = "your_global_variable", 
      value = input$id, 
      envir = .GlobalEnv
   )
})