extendInputType: Add Custom Input Types for a Survey

Description Usage Arguments Value See Also Examples

View source: R/extend_shinysurveys.R

Description

Add Custom Input Types for a Survey

Usage

1
extendInputType(input_type, extension)

Arguments

input_type

A string of the input type supplied in the data frame of questions.

extension

A shiny input type not natively supported by shinysurveys. See the examples section for more information.

Value

NA; used to register custom input types for use with a shiny survey.

See Also

surveyID

surveyLabel

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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Register a slider input to {shinysurveys} with a custom minimum and maximum value.

extendInputType("slider", {
  shiny::sliderInput(
    inputId = surveyID(),
    label = surveyLabel(),
    min = 1,
    max = 10,
    value = 5
    )
  })

# Define a question as normal with the `input_type` set to the custom slider type defined above.
slider_question <- data.frame(question = "On a scale from 1-10,
how much do you love sushi?",
option = NA,
input_type = "slider",
input_id = "sushi_scale",
dependence = NA,
dependence_value = NA,
required = TRUE)

# Watch it in action
if (interactive()) {
ui <- fluidPage(
  surveyOutput(df = slider_question, "Sushi Scale Example")
)

server <- function(input, output, session) {
  renderSurvey()
}

shinyApp(ui, server)

}



# Register a date input to {shinysurveys},
# limiting possible dates to a twenty-day period.

extendInputType("date", {
  shiny::dateInput(
    inputId = surveyID(),
    value = Sys.Date(),
    label = surveyLabel(),
    min = Sys.Date()-10,
    max = Sys.Date()+10
  )
})

# Define a question as normal with the `input_type` set to
# the custom date type defined above.

date_question <- data.frame(question = "When do you graduate?",
option = NA,
input_type = "date",
input_id = "grad_date",
dependence = NA,
dependence_value = NA,
required = FALSE)

# Watch it in action
if (interactive()) {
ui <- fluidPage(
  surveyOutput(df = date_question, "Date Input Extension Example")
)

server <- function(input, output, session) {
  renderSurvey()
}

shinyApp(ui, server)
}


# Combine both custom input types:

if (interactive()) {
ui <- fluidPage(
  surveyOutput(df = rbind(slider_question, date_question),
  "Date & Slider Input Extension Example")
)

server <- function(input, output, session) {
  renderSurvey()
}

shinyApp(ui, server)
}

shinysurveys documentation built on July 11, 2021, 9:06 a.m.