dq_add_selectize_options: Adds selectizeOptions to a column of rhandsontable

Description Usage Arguments Value Author(s) Examples

View source: R/hot_helpers.R

Description

dq_add_selectize_options adds selectizeOptions to a column of a rhandsontable to be used with the selectize editor. Especially useful if each cell should have individual dropdowns. It will also set the type and editor for the specified column.

dq_as_selectize_options converts the given vector of options into a proper selectize options list. Names of the given vector will be used to specify labels for the options. Further selectize attributes can be set via additional named parameters.

Usage

1
2
3

Arguments

hot

rhandsontable object

rows

vector of row indices, NULL means the whole column will be filled

col

column index or name, must be scalar

options

character vector or list to be used as selectize options, names will be used as labels for the options, dq_add_selectize_options can also handle lists of vectors, where each vector will be used to specify the options of one cell

...

additional parameters to be passed to selectize

Value

dq_add_selectize_options: updated rhandsontable object

dq_as_selectize_options: list containing all options and additional settings

Author(s)

richard.kunze

Examples

 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
## Only run examples in interactive R sessions
if (interactive()) {

library(rhandsontable)
library(shiny)
hw <- c("Hello", "my", "funny", "world!",
  "Those", "are", "some", "really", "random", "words!")

options <- lapply(1:10, function(x) c(Name1 = sample(hw, 1),
  Name2 = sample(hw, 1), Name3 = sample(hw, 1)))
ch <- sample(hw, 3)
names(ch) <- sample(hw, 3)
selectize <- dq_as_selectize_options(ch, create = TRUE)

empty <- rep("", 10)
df <- data.frame(Unlabled=empty, Labled=empty,
  Multiple=empty, stringsAsFactors = F)

shinyApp(
  ui = fluidPage(
    dq_space(),
    rHandsontableOutput("randomTable")
  ),
  server = function(input, output) {
    output$randomTable <- renderRHandsontable({
      rhandsontable(df, stretchH = "all") %>%
        dq_add_selectize_options(NULL, 1, lapply(options, unname)) %>%
        hot_col(2, editor = "selectize", selectizeOptions = selectize) %>%
        dq_add_selectize_options(NULL, "Multiple", options, maxItems = 2)
    })
  }
)

}

dqshiny documentation built on May 2, 2019, 1:43 p.m.