Guest User

Untitled

a guest
Jan 26th, 2018
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. ui1 <- function(){
  2. tagList(h2("Hello", align = "center"),
  3. div(id = "login",
  4. wellPanel(textInput("userName", "Username"),
  5. passwordInput("passwd", "Password"),
  6. br(),actionButton("Login", "Log in"),
  7. actionLink("Regis","Register"),
  8. actionLink("FORGET","Forgot"))),
  9. tags$style(type="text/css", "#login {font-size:10px; text-align: left;position:absolute;top: 45%;left: 50%;margin-top: -100px;margin-left: -150px;}")
  10. )}
  11. ui2 <- function(){
  12. tagList(tabPanel(""),
  13. pageWithSidebar(
  14. headerPanel(
  15. ""
  16. ),
  17. sidebarPanel
  18. (
  19. tags$head(tags$style(type="text/css", ".well { max-width: 280px; }")),
  20. selectInput("CC","Please select a course", choices = c("E"=1,"M"=2)),
  21. selectInput("SP","Bla Bla", choices = c("AA"=1,"BB"=2,"CC"=3,"DD"=4,"EE"=5)),
  22. numericInput("UT",label = "Available", value = 10, min = 10),
  23. actionButton("RM", label = "RM",style="width:32%;"),
  24. actionButton("Cont", label = "Cont",style="width:32%;"),
  25. hidden(actionButton("strt", label = "Start",style="width:32%;")),
  26. actionButton("logout", "Logout",style="color: red; width:32%;")
  27. ),
  28. mainPanel(tableOutput('path'),
  29. shinyjs::useShinyjs(),
  30. hidden(actionButton("nxt", label = "Done/Next",style="color: blue;width:15%;float:right")),
  31. hidden(selectInput("test", "Was it easy?", list(" "="","No" = "No", "Not_sure" = "Not sure", "Yes" = "Yes"),selected = NULL))
  32. )
  33. )
  34. )
  35. }
  36. server = (function(input, output,session) {
  37. USER <- reactiveValues(Logged = Logged)
  38. observe({
  39. if (USER$Logged == FALSE) {
  40. if (!is.null(input$Login)) {
  41. if (input$Login > 0) {
  42. Username <- isolate(input$userName)
  43. Password <- isolate(input$passwd)
  44. query <- sprintf({"
  45. SELECT rowid
  46. FROM users
  47. WHERE username='%s' and password ='%s'"},
  48. Username, Password, serialize=F)
  49. db <- RSQLite::dbConnect(RSQLite::SQLite(), dbname="db.sqlite")
  50. user <- RSQLite::dbGetQuery(db, query)
  51. RSQLite::dbDisconnect(db)
  52. if ( length(user$rowid)==1 ) {
  53. USER$Logged <- TRUE
  54. }
  55. }
  56. }
  57. }
  58. })
  59. observe({
  60. if (USER$Logged == FALSE) {
  61. output$page <- renderUI({div(class="outer",do.call(bootstrapPage,c("",ui1())))})
  62. }
  63. if (USER$Logged == TRUE)
  64. {
  65. output$page <- renderUI({div(class="outer",do.call(navbarPage,c(inverse=TRUE,title = paste("Welcome", isolate(input$userName)," !"),ui2())))})
  66. shinyjs::hide("nxt")
  67. shinyjs::hide("test")
  68. print(ui)
  69. }
  70. })
  71. })
  72. ui = (htmlOutput("page"))
  73.  
  74. library(shiny)
  75. library(RSQLite)
  76. db <- dbConnect(SQLite(), dbname="db.sqlite")
  77. dbSendQuery(conn = db,"CREATE TABLE users (username TEXT, password TEXT, email TEXT)")
  78. dbSendQuery(db, "INSERT INTO users ( username, password, email) VALUES ( 'ester', 'silva', 'abc@gmail.com');")
Add Comment
Please, Sign In to add comment