From e254a181c2d471e264bfb4410703f6211717b2ca Mon Sep 17 00:00:00 2001 From: fozy81 Date: Mon, 4 Apr 2016 22:40:48 +0100 Subject: [PATCH 1/7] adding more input types --- R/shinyform.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/shinyform.R b/R/shinyform.R index 4eec78e..f632519 100644 --- a/R/shinyform.R +++ b/R/shinyform.R @@ -123,7 +123,11 @@ formUI <- function(formInfo) { input <- numericInput(ns(question$id), NULL, 0) } else if (question$type == "checkbox") { input <- checkboxInput(ns(question$id), label, FALSE) - } + } else if (question$type == "date") { + dateInput(ns(question$id), label, FALSE)} + else if (question$type == "slider") { + sliderInput(ns(question$id), label, min = question$min, max = question$max, value = question$value, + step = question$step)} div( class = "sf-question", From 7b583c911e1ba9f8831e46973cccb2a73896f219 Mon Sep 17 00:00:00 2001 From: fozy81 Date: Mon, 4 Apr 2016 22:43:56 +0100 Subject: [PATCH 2/7] new input types --- R/shinyform.R | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/R/shinyform.R b/R/shinyform.R index f632519..da0db48 100644 --- a/R/shinyform.R +++ b/R/shinyform.R @@ -118,16 +118,47 @@ 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") { - dateInput(ns(question$id), label, FALSE)} - else if (question$type == "slider") { - sliderInput(ns(question$id), label, min = question$min, max = question$max, value = question$value, - step = question$step)} + 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) + } + 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) + } div( class = "sf-question", From 6aaf03db1376ffab38c4e388a47ff592e14a86e0 Mon Sep 17 00:00:00 2001 From: fozy81 Date: Mon, 4 Apr 2016 23:01:11 +0100 Subject: [PATCH 3/7] readme update to include updated input types --- README.md | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index da925fe..fd74bed 100644 --- a/README.md +++ b/README.md @@ -104,11 +104,26 @@ 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", # placeholder not working? + 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) ), storage = list( type = STORAGE_TYPES$FLATFILE, From 436090f0d465443c67f47d546e11b0626ebd0177 Mon Sep 17 00:00:00 2001 From: fozy81 Date: Mon, 4 Apr 2016 23:04:27 +0100 Subject: [PATCH 4/7] removing comment --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fd74bed..02dd08c 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ library(shinyforms) basicInfoForm <- list( id = "basicinfo", questions = list( - list(id = "name", type = "text", title = "Name", mandatory = TRUE, value = "", placeholder = "Add full name here", # placeholder not working? + 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"), From cfe845ea23cca9359972849512ee62bf22440b2a Mon Sep 17 00:00:00 2001 From: fozy81 Date: Fri, 15 Apr 2016 23:36:22 +0100 Subject: [PATCH 5/7] added image 'question' type --- R/shinyform.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/shinyform.R b/R/shinyform.R index da0db48..b6efca5 100644 --- a/R/shinyform.R +++ b/R/shinyform.R @@ -150,6 +150,7 @@ formUI <- function(formInfo) { 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, @@ -211,7 +212,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") ), From 5c67453e551b46a126865cdcde498e30e75cdc88 Mon Sep 17 00:00:00 2001 From: fozy81 Date: Fri, 15 Apr 2016 23:47:56 +0100 Subject: [PATCH 6/7] readme update --- R/shinyform.R | 10 ++++++++++ README.md | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/R/shinyform.R b/R/shinyform.R index b6efca5..5aaaa12 100644 --- a/R/shinyform.R +++ b/R/shinyform.R @@ -160,6 +160,16 @@ formUI <- function(formInfo) { 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( class = "sf-question", diff --git a/README.md b/README.md index 02dd08c..e87577b 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,11 @@ basicInfoForm <- list( "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" From 68890d2a100a020f79c1af1ed45b592f49e6a28d Mon Sep 17 00:00:00 2001 From: fozy81 Date: Fri, 15 Apr 2016 23:48:19 +0100 Subject: [PATCH 7/7] readme update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e87577b..edce183 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ basicInfoForm <- list( 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) + 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"),