zapier/shinyforms

Name: shinyforms

Owner: Zapier

Description: Easily create questionnaire-type forms with Shiny

Forked from: daattali/shinyforms

Created: 2017-09-22 18:03:37.0

Updated: 2017-09-22 18:03:39.0

Pushed: 2017-09-22 19:05:22.0

Homepage: null

Size: 22

Language: R

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

shinyforms - Easily create questionnaire-type forms with Shiny

saythanks

Copyright 2016 Dean Attali. Licensed under the MIT license.

Note: This is very much a work in progress in its baby stages. This package only has one day's worth of work in it. It's functional and works on a basic level, but there are many many more awesome things planned. Work on this package is temporarily halted until I find some time to work on it.

What does shinyforms do?

The idea of shinyforms is to let you create questions/polls/surveys as Shiny apps very easily. Kind of like mimicking a Google Form.

But, why?

Good question. You should read my blog post where I discuss how to mimick Google Forms with Shiny, and why I originally needed to do it. I've created a few Shiny apps that request user input and save it somewhere, and I wanted to make it super streamlined for anyone else to do so in the future. You can see an live example of a Shiny form here.

How do I use this?

First, install this package from GitHub

stall.packages("devtools")
ools::install_github("daattali/shinyforms")

Then create your list of questions. Each question is a list with an id, type, title, and mandatory (mandatory is FALSE by default)

ary(shiny)
ary(shinyforms)

tions <- list(
st(id = "name", type = "text", title = "Name", mandatory = TRUE),
st(id = "age", type = "numeric", title = "Age"),
st(id = "favourite_pkg", type = "text", title = "Favourite R package"),
st(id = "terms", type = "checkbox", title = "I agree to the terms")

Then create your form information, which has an id, the list of questions, and the storage type (where responses get saved).

Info <- list(
 = "basicinfo",
estions = questions,
orage = list(
# Right now, only flat file storage is supported
type = STORAGE_TYPES$FLATFILE,
# The path where responses are stored
path = "responses"


That's all the information we need. Now we can add the form to a Shiny app by simply calling formUI() and formServer() from our Shiny apps' UI and server:

- fluidPage(
rmUI(formInfo)


er <- function(input, output, session) {
rmServer(formInfo)


yApp(ui = ui, server = server)

Of course you could put more stuff in the app, but this is the beauty of it, the form is a “module” that you can just plug into any Shiny app anywhere you want. Every time you submit a response, it will be saved as a file in the responses directory. This example is the most basic usage.

Current features Future features

You can see all the features I want to support here (but it might take some time because I can't devote too much time to this package right now).

Another example

This example is similar to the previous one, but illustrates a few more features. It shows how to have two forms in one app, and how to use the admin viewing ability.

ary(shiny)
ary(shinyforms)

fine the first form: basic information
cInfoForm <- list(
 = "basicinfo",
estions = 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 = "favourite_pkg", type = "text", title = "Favourite R package"),
list(id = "terms", type = "checkbox", title = "I agree to the terms")

orage = list(
type = STORAGE_TYPES$FLATFILE,
path = "responses"

me = "Personal info",
ssword = "shinyforms",
set = TRUE,
lidations = list(
list(condition = "nchar(input$name) >= 3",
     message = "Name must be at least 3 characters"),
list(condition = "input$terms == TRUE",
     message = "You must agree to the terms")



fine the second form: soccer
erFormInfo <- list(
 = "soccerform",
estions = list(
list(id = "team", type = "text", title = "Favourite soccer team"),
list(id = "player", type = "text", title = "Favourite player")

orage = list(
type = STORAGE_TYPES$FLATFILE,
path = "soccer"

ltiple = FALSE


- fluidPage(
("shinyforms example"),
bsetPanel(
tabPanel(
  "Basic info",
  formUI(basicInfoForm)
),
tabPanel(
  "Soccer",
  formUI(soccerFormInfo)
)



er <- function(input, output, session) {
rmServer(basicInfoForm)
rmServer(soccerFormInfo)


yApp(ui = ui, server = server)

Notice how easy this is? After defining the forms with R lists, it's literally two function calls for each form to get it set up. A couple things to note: first, the soccer form uses the multiple = FALSE option, which means a user can only submit once (if you restart the Shiny app, the same user is able to submit the form again). Secondly, the first form uses the password option, which means that the admin table will be available IF you add ?admin=1 to the URL. To see the responses from the admin table, click on “Show responses” and type in the password “shinyforms”. This app also uses several other features.

Feedback

If you think you could have a use for shinyforms, please do let me know or file an issue. Don't be shy!

Notes

Please don't look at the code, it's hideous! This was done at runconf16 in just a few very short hours so it needs to be cleaned up quite a bit. Also, since so little time was spent building this package so far, it's very likely that the API will change. I'm completely open for input.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.