# NOT RUN {
library(shiny)
library(firebase)
# modals
register <- modalDialog(
title = "Register",
textInput("email_create", "Your email"),
passwordInput("password_create", "Your password"),
footer = actionButton("create", "Register")
)
sign_in <- modalDialog(
title = "Sign in",
textInput("email_signin", "Your email"),
passwordInput("password_signin", "Your password"),
footer = actionButton("signin", "Sign in")
)
ui <- fluidPage(
useFirebase(), # import dependencies
actionButton("register_modal", "Register"),
actionButton("signin_modal", "Signin"),
plotOutput("plot")
)
server <- function(input, output){
f <- FirebaseEmailPassword$new()
# open modals
observeEvent(input$register_modal, {
showModal(register)
})
observeEvent(input$signin_modal, {
showModal(sign_in)
})
# create the user
observeEvent(input$create, {
f$create(input$email_create, input$password_create)
})
# check if creation sucessful
observeEvent(f$get_created(), {
created <- f$get_created()
if(created$success){
removeModal()
showNotification("Account created!", type = "message")
} else {
showNotification("Error!", type = "error")
}
# print results to the console
print(created)
})
observeEvent(input$signin, {
removeModal()
f$sign_in(input$email_signin, input$password_signin)
})
output$plot <- renderPlot({
f$req_sign_in()
plot(cars)
})
}
# }
# NOT RUN {
shinyApp(ui, server)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab