Skip to content

Instantly share code, notes, and snippets.

@GuyliannEngels
Last active May 7, 2020 13:52
Show Gist options
  • Select an option

  • Save GuyliannEngels/9b75784e70d87895d96760b9be62cea0 to your computer and use it in GitHub Desktop.

Select an option

Save GuyliannEngels/9b75784e70d87895d96760b9be62cea0 to your computer and use it in GitHub Desktop.
ShinyApp avec validation du login et de l'email
library(shiny)
library(shinyFeedback)
# note : tab_user peut être facilement changé par une table des utilisateurs du cours,...
tab_user <- tibble::tibble(
login = c("AnakinSkywalker", "LeiaOrgana"),
email = c("anakin.skywalker@student.umons.ac.be", "leia.organa@student.umons.ac.be"))
ui <- fluidPage(
shinyFeedback::useShinyFeedback(),
fluidRow(
column(4,
h3("Version actuelle"),
textInput("user", "Utilisateur :", ""),
textInput("email", "Email :", "", placeholder = "prenom.nom@student.umons.ac.be")
),
column(4,
h3("Version 1"),
selectInput("user1", "Utilisateur :", c("", tab_user$login)),
selectInput("email1", "Email :", c("", tab_user$email))
),
column(4,
h3("Version 2"),
shinyFeedback::useShinyFeedback(),
textInput("user2", "Utilisateur :", ""),
textInput("email2", "Email :", "", placeholder = "prenom.nom@student.umons.ac.be"),
actionButton("check", "Vérification des infos"),
helpText(
"Lors de la vérification, tu peux avoir une erreur",
"si ton login est incorrecte ou ton adresse mail",
"si tu n'as pas accès à la base de données"),
strong(textOutput("check_name"))
)),
hr(),
h3("Dans la base de données"),
fluidRow(
column(4,
textOutput("out_user"),
textOutput("out_email")
),
column(4,
textOutput("out_user1"),
textOutput("out_email1")
),
column(4,
textOutput("out_user2"),
textOutput("out_email2"))
)
)
server <- function(input, output, session) {
output$out_user <- renderText({
paste("login", input$user)
})
output$out_email <- renderText({
paste("email : ", input$email)
})
output$out_user1 <- renderText({
paste("login", input$user1)
})
output$out_email1 <- renderText({
paste("email : ", input$email1)
})
observeEvent(input$user2,
shinyFeedback::feedbackWarning(
"user2",
input$user2 == "",
"Complétez votre login")
)
output$out_user2 <- renderText({
paste("login : ", input$user2)
})
observeEvent(input$email2,
shinyFeedback::feedbackWarning(
"email2",
input$email2 == "",
"Complétez votre email")
)
output$out_email2 <- renderText({
paste("email : ", input$email2)
})
response <- eventReactive(input$check, {
if (isTRUE(
any(tab_user$login %in% input$user2) & any(tab_user$email %in% input$email2)
)) {
res <- "Tes données sont validées, lance toi dans to learnR"
} else {
res <- "STOP !!!!"
}
res
})
output$check_name <- renderText({
response()
})
}
app <- shinyApp(ui, server)
runApp(app)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment