diff --git a/R/shinyform.R b/R/shinyform.R index 4eec78e..5aaaa12 100644 --- a/R/shinyform.R +++ b/R/shinyform.R @@ -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( @@ -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") ), diff --git a/README.md b/README.md index da925fe..edce183 100644 --- a/README.md +++ b/README.md @@ -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"