Skip to content

Commit

Permalink
app state
Browse files Browse the repository at this point in the history
  • Loading branch information
epijim committed May 3, 2019
1 parent d41d44c commit d758e47
Show file tree
Hide file tree
Showing 10 changed files with 5,790 additions and 26 deletions.
38 changes: 22 additions & 16 deletions app.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,33 @@ invited <- read_csv(

# Define UI for application that draws a histogram
ui <- fluidPage(
# GOOGLE ANALYTICS
tags$head(includeScript("gs.js")),

# Application title
titlePanel("R/Pharma registration"),

# Their email
textInput("entered_email", "Please enter your email address", ""),
textInput("entered_email", "Please enter the email address we used to contact you", ""),

# Industry
radioButtons(
"industry",
"Please choose the research type that best represents you:",
c("Regulatory body",
"Pharma company",
"Contract Research Organisation",
"Non-profit",
"Academic",
"Student")),
helpText("Spaces are very limited, so please only register if you plan to attend"),
# radioButtons(
# "industry",
# "Please choose the research type that best represents you:",
# c("Pharma company",
# "Regulatory body",
# "Contract Research Organisation",
# "Non-profit",
# "Academic",
# "Student")),
helpText(
a("Please click here to view the terms and conditions",
href = "http://rinpharma.com/terms")
),
helpText("Spaces are very limited, so please only register if you plan to attend"),
checkboxInput(
"confirmed",
"I confirm that I plan to attend R/Pharma on August 15th and 16th",
"I confirm that I accept the terms linked to above and I plan to attend R/Pharma on August 15th and 16th",
FALSE),
actionButton("submit", "Submit"),

Expand Down Expand Up @@ -106,7 +112,7 @@ server <- function(input, output) {
# check if invited
validate(
need(tolower(input$entered_email) %in% tolower(invited$Email),
"Sorry, your email is not on the list of invited people")
"Sorry, your email is not on the list of invited people, please use the form at rinpharma.com to get in contact.")
)

# check they agree
Expand All @@ -123,13 +129,13 @@ server <- function(input, output) {
# check if they are already registered
validate(
need(!tolower(input$entered_email) %in% tolower(old_data$Email),
paste(input$entered_email,"is already registered."))
paste(input$entered_email,"is already registered. See you soon in Boston."))
)

# Merge with data
data <- data.frame(
Email = tolower(input$entered_email),
Industry = input$industry,
Industry = "POST REMOVAL",
Attending = input$confirmed,
Time = Sys.time(),
stringsAsFactors = FALSE
Expand Down Expand Up @@ -157,7 +163,7 @@ server <- function(input, output) {
input$submit
output <- formData()
paste0(
output$Name,", thank you for registering."
output$Name,", thank you for registering. See you in Boston."
)
})
}
Expand Down
5 changes: 5 additions & 0 deletions gs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-109863434-1');
1 change: 1 addition & 0 deletions mixer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.httr-oauth
233 changes: 233 additions & 0 deletions mixer/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#

library(shiny)
library(tidyverse)
library(magrittr)
library(googlesheets)

# gs_auth()

## Database connect ------

## Database functions ------------

table <- "RinPharmaMixer"

saveData <- function(data,table) {
# Grab the Google Sheet
sheet <- gs_title(table)
# Add the data as a new row
gs_add_row(sheet, input = data)
}

loadData <- function(table) {
# Grab the Google Sheet
sheet <- gs_title(table)
# Read the data
gs_read_csv(sheet)
}

### Load coming

sheet <- gs_title("RinPharmaRegistered")
# Read the data
registered <- gs_read_csv(sheet) %>%
filter(Name != "test")

### UI ----------

# Define UI for application that draws a histogram
ui <- fluidPage(

# Application title
titlePanel("R/Pharma workshop and mixer registration"),

sidebarPanel(

# Their email
textInput("entered_email", "Please enter the email address we used to contact you", ""),

helpText("Come join fellow R/Pharma Conference attendees for an informal mixer hosted by Metrum Research Group following our day one programming!"),
helpText("Time: Wednesday August 15th from 6:00-7:30pm."),

radioButtons("confirmed", "Do you plan to attend the mixer?",
c("Yes" = "Yes",
"No" = "No")
),
hr(),
radioButtons("SessionOne", "Would you like to sign up for an 8am workshop on Wednesday (Aug 15th)?",
c("No" = "No",
"Keeping things Peachy when Shiny gets Hairy" = "Foos",
"Analyzing Clinical Trials Data with R Adrian Waddell" = "Waddell",
"Bayesian Models for Smaller Trial Sizes - Stan with R for analysis" = "Lee",
"Moving Fast Without Breaking Things: Navigating the R Ecosystem in an Enterprise Environment" = "Pastoor"
)
),
hr(),
radioButtons("SessionTwo", "Would you like to sign up for an 8am workshop on Thursday (Aug 16th)?",
c("No" = "No",
"Interactive data visualization with R, plotly, and dashR" = "Sievert",
"The Challenges of Validating R" = "Nicholls",
" The largest Shiny application in the world. Roche.Diagnostics.bioWARP" = "Wolf"
)
),
actionButton("submit", "Submit"),

hr(),

textOutput("response"),
width = 6
),
mainPanel(
h3("Summary of open spots"),
helpText("This table will not update when you press submit"),
tableOutput("table"),width = 6
)
)

# Define server logic
server <- function(input, output) {

old_data <- reactive({
### previous replies
sheet <- gs_title("RinPharmaMixer")
# Read the data
old_data <- gs_read_csv(sheet) %>%
filter(Name != "test")

old_data
})


the_table <- reactive({
tibble(
Workshop = c(
"The largest Shiny application in the world. Roche.Diagnostics.bioWARP",
"The Challenges of Validating R",
"Interactive data visualization with R, plotly, and dashR",
"Keeping things Peachy when Shiny gets Hairy",
"Analyzing Clinical Trials Data with R",
"Bayesian Models for Smaller Trial Sizes - Stan with R for analysis.",
"Moving Fast Without Breaking Things: Navigating the R Ecosystem in an Enterprise Environment"
),
Lead = c("Wolf","Nicholls","Sievert","Foos","Waddell","Lee","Pastoor"),
Spaces = c(20,45,60,45,60,20,30)
) %>%
left_join(
rbind(
old_data() %>%
select(Name,Email,Lead = SessionOne),
old_data() %>%
select(Name,Email,Lead = SessionTwo)
) %>%
group_by(Lead) %>%
summarise(Attending = n()),
by = "Lead"
) %>%
mutate(
Attending = ifelse(is.na(Attending),0,Attending),
Attending = as.integer(Attending),
`Spaces left` = as.integer(Spaces - Attending)
) %>%
select(Workshop,Attending,`Spaces left`,Lead)
})

full_workshops <- reactive({
the_table() %>%
filter(`Spaces left` == 0) %$%
Lead
})

output$table <- renderTable({
the_table() %>% select(-Lead)
})

# Whenever a form is submitted aggregate all form data
formData <- eventReactive(input$submit,{

withProgress(message = 'Processing registration', value = 0, {

incProgress(0.2, detail = paste("Running input checks"))

# check there is an email @
validate(
need(grep("@",input$entered_email) == 1,
"Please enter an email address")
)

# check if invited
validate(
need(tolower(input$entered_email) %in% tolower(registered$Email),
"Sorry, your email is not on the list of registered people, please use the form at rinpharma.com to get in contact.")
)

incProgress(0.2, detail = paste("Checking if there is space in the workshops"))

# check if workshop full
validate(
need(!c(input$SessionOne,input$SessionTwo) %in% full_workshops(),
"Sorry, one of the workshops you selected is full.")
)

incProgress(0.2, detail = paste("Checking if you are already registered"))

# check if they are already registered
validate(
need(!tolower(input$entered_email) %in% tolower(old_data()$Email),
paste(input$entered_email,"is already registered. See you soon in Boston."))
)

validate(
need(input$submit == 1,
paste(input$entered_email,"you already pressed submit once. Please reload the app if you got an error the first time."))
)

# Merge with data
data <- data.frame(
Email = tolower(input$entered_email),
Industry = "POST REMOVAL",
Attending = input$confirmed,
Time = Sys.time(),
SessionOne = input$SessionOne,
SessionTwo = input$SessionTwo,
stringsAsFactors = FALSE
) %>%
left_join(
registered %>% select(Name, Email),
by = "Email"
) %>%
select(
Name,Email,Time,Attending,SessionOne,SessionTwo
)
})
data
})

# When the Submit button is clicked, save the form data
observeEvent(input$submit,{
# check if they are already registered
tosave <- formData()
withProgress(message = 'Saving registration', value = 1, {
saveData(tosave,"RinPharmaMixer")
})
})

output$response <- renderText({
input$submit
output <- formData()
paste0(
output$Name,", thank you for registering. See you in Boston."
)
})
}

# Run the application
shinyApp(ui = ui, server = server)

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Registrations
title: Registrations
username:
account: epijim
server: shinyapps.io
hostUrl: https://api.shinyapps.io/v1
appId: 369479
bundleId: 1508004
url: https://epijim.shinyapps.io/Registrations/
when: 1532982971.02823
asMultiple: FALSE
asStatic: FALSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Registrations
title: Registrations
username:
account: epijimapps
server: shinyapps.io
hostUrl: https://api.shinyapps.io/v1
appId: 365591
bundleId: 1454944
url: https://epijimapps.shinyapps.io/Registrations/
when: 1530210193.3828
asMultiple: FALSE
asStatic: FALSE
12 changes: 12 additions & 0 deletions mixer/rsconnect/shinyapps.io/epijim/mixer.dcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: mixer
title: mixer
username:
account: epijim
server: shinyapps.io
hostUrl: https://api.shinyapps.io/v1
appId: 392115
bundleId: 1534178
url: https://epijim.shinyapps.io/mixer/
when: 1534240555.76692
asMultiple: FALSE
asStatic: FALSE
Loading

0 comments on commit d758e47

Please sign in to comment.