Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 deletions R/shinyform.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,57 @@ formUI <- function(formInfo) {
}

if (question$type == "text") {
input <- textInput(ns(question$id), NULL, "")
input <- textInput(ns(question$id), label = NULL, value = question$value, placeholder = question$placeholder,
width = question$width)
} else if (question$type == "numeric") {
input <- numericInput(ns(question$id), NULL, 0)
input <- numericInput(ns(question$id), label = NULL, value = question$value, min = question$min,
max = question$max, step = question$step, width = question$width)
} else if (question$type == "checkbox") {
input <- checkboxInput(ns(question$id), label, FALSE)
input <- checkboxInput(ns(question$id), label, value = question$value, width = question$width)
} else if (question$type == "dateRange") {
input <- dateRangeInput(ns(question$id), label = NULL, start = question$start, end = question$end,
min = question$min, max = question$max, format = question$format, startview = question$startview,
weekstart = question$weekstart, language = question$language, width = question$width)
} else if (question$type == "date") {
input <- dateInput(ns(question$id), label = NULL, value = question$value,
min = question$min, max = question$max, format = question$format, startview = question$startview,
weekstart = question$weekstart, language = question$language, width = question$width)
} else if (question$type == "slider") {
input <- sliderInput(ns(question$id), label = NULL, min = question$min, max = question$max,
value = question$value, step = question$step, round = question$round,
ticks = question$ticks, animate = question$animate,
width = question$width, sep = question$sep, pre = question$pre, post = question$post,
timeFormat = question$timeFormat,
timezone = question$timezone, dragRange = question$dragRange)
} else if (question$type == "radio") {
input <- radioButtons(ns(question$id), choices = question$choices, NULL)
} else if (question$type == "select") {
input <- selectInput(ns(question$id), label = NULL, choices = question$choices, selected = question$selected,
multiple = question$multiple, selectize = question$selectize, width = question$width,
size = question$size)
} else if (question$type == "checkboxGroup") {
input <- checkboxGroupInput(ns(question$id), label = NULL, choices = question$choices, selected = question$selected,
inline = question$inline, width = question$width)
}
# create textarea input html:
textareaInput <- function(id, value, placeholder, title, label, width = NULL){
div(class = "form-group shiny-input-container", style = if (!is.null(width))
paste0("width: ", validateCssUnit(width), ";"), tags$textarea(id = id, rows = 3, cols = 41, type = "textarea", value = value,
placeholder = placeholder))
}

if (question$type == "textarea") {
input <- textareaInput(ns(question$id), value = question$value, placeholder = question$placeholder)
}
# image only, no input
imageInput <- function(src = "https://upload.wikimedia.org/wikipedia/commons/thumb/f/f6/Steve_Wozniak.jpg/800px-Steve_Wozniak.jpg", width = 300, height= 300) {
img(src = src,
height = 400, width = 400)
}

if (question$type == "image") {
input <- imageInput(src = question$src,
height = question$height, width = question$width)
}

div(
Expand Down Expand Up @@ -176,7 +222,7 @@ formUI <- function(formInfo) {
div(
class = "pw-box", id = ns("pw-box"),
inlineInput(
passwordInput(ns("adminpw"), NULL, placeholder = "Password")
passwordInput(ns("adminpw"), NULL)
),
actionButton(ns("submitPw"), "Log in")
),
Expand Down
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,31 @@ library(shinyforms)
basicInfoForm <- list(
id = "basicinfo",
questions = list(
list(id = "name", type = "text", title = "Name", mandatory = TRUE,
hint = "Your name exactly as it is shown on your passport"),
list(id = "age", type = "numeric", title = "Age", mandatory = FALSE),
list(id = "name", type = "text", title = "Name", mandatory = TRUE, value = "", placeholder = "Add full name here",
hint = "Your name exactly as it is shown on your passport", width = 350),
list(id = "age", type = "numeric", title = "Age", min = 0, max = 150, value = 0, step = 1, mandatory = FALSE, hint = "Age between: 0-150"),
list(id = "favourite_pkg", type = "text", title = "Favourite R package"),
list(id = "terms", type = "checkbox", title = "I agree to the terms")
),
list(id = "slider", type = "slider", title = "Slider Input", min = 1, max = 10,
value = 1, ticks = TRUE, mandatory = FALSE),
list(id = "date", type = "date", title = "Date"),
list(id = "terms", type = "checkbox", title = "I agree to the terms"),
list(id = "radios", type = "radio", title = "Radio buttons",
choices = c("Normal" = "norm",
"Uniform" = "unif",
"Log-normal" = "lnorm",
"Exponential" = "exp")),
list(id = "daterange", type = "dateRange", title = "Date Range"),
list(id = "checkboxGroupInput", type = "checkboxGroup", title = "checkboxGroup", choices = c("Cylinders" = "cyl",
"Transmission" = "am", "Gears" = "gear"),inline = FALSE),
list(id = "select", type = "select", title = "select input", choices = c("Cylinders" = "cyl",
"Transmission" = "am", "Gears" = "gear"), multiple = FALSE, selectize = TRUE),
list(id = "area", type = "textarea", title = "Area Box", mandatory = FALSE, value = "", placeholder = "description...", # placeholder not working?
hint = "free text description", width = 400),
list(id = "image", type = "image", src = "https://upload.wikimedia.org/wikipedia/en/d/d4/Mickey_Mouse.png", height = 300, width = 300),
list(id = "test", type = "select", title = "How's this?", choices = c("Batman" = "Bat",
"Superman" = "Super", "Mickey Mouse" = "Mickey"),

multiple = FALSE, selectize = TRUE)),
storage = list(
type = STORAGE_TYPES$FLATFILE,
path = "responses"
Expand Down