File: multiparam_selectize.R

package info (click to toggle)
r-cran-shinystan 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,172 kB
  • sloc: sh: 15; makefile: 7
file content (64 lines) | stat: -rw-r--r-- 1,719 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
output$ui_multiparam_selectize <- renderUI({
  choices <- make_param_list_with_groups_sort()
  selected <- c(input$params_to_plot)
  selectizeInput(
    "params_to_plot",
    label = h5("Select or enter parameter names"),
    width = '100%',
    choices = choices,
    multiple = TRUE
  )
})


# updating the choices and selected for the selectizeInput input$params_to_plot
# when the sorting option is changed in input$param_plot_sort_j or when
# parameters added by regex search

copy_params_to_plot <- reactive({
  copy <- input$params_to_plot
  if (is.null(copy) || !length(copy))
    NULL
  else
    copy
})

observe({
  x <- input$param_plot_sort_j
  choices <- make_param_list_with_groups_sort()
  selected <- copy_params_to_plot()
  selected <- .update_params_with_groups(selected, PARAM_NAMES)
  updateSelectizeInput(
    session,
    inputId = "params_to_plot",
    choices = choices,
    selected = selected
  )
})

observeEvent(input$param_plot_regex, {
  pattern <- input$params_to_plot_regex
  if (pattern != "") {
    choices <- make_param_list_with_groups_sort()
    selected <- copy_params_to_plot()
    selected <- .update_params_with_groups(selected, PARAM_NAMES)
    if (.test_valid_regex(pattern)) {
      selected <- .update_params_with_regex(selected, PARAM_NAMES, pattern)
      updateSelectizeInput(
        session,
        inputId = "params_to_plot",
        choices = choices,
        selected = selected
      )
    }
  }
})

output$invalid_regex <- renderText({
  pattern <- input$params_to_plot_regex
  if (length(pattern)) {
    msg <- "Invalid regular expression.\nYou might need to add the escape character '\\' ."
    validate(need(.test_valid_regex(pattern), message = msg))
  }
})