Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ui1 <- function(){
- tagList(h2("Hello", align = "center"),
- div(id = "login",
- wellPanel(textInput("userName", "Username"),
- passwordInput("passwd", "Password"),
- br(),actionButton("Login", "Log in"),
- actionLink("Regis","Register"),
- actionLink("FORGET","Forgot"))),
- tags$style(type="text/css", "#login {font-size:10px; text-align: left;position:absolute;top: 45%;left: 50%;margin-top: -100px;margin-left: -150px;}")
- )}
- ui2 <- function(){
- tagList(tabPanel(""),
- pageWithSidebar(
- headerPanel(
- ""
- ),
- sidebarPanel
- (
- tags$head(tags$style(type="text/css", ".well { max-width: 280px; }")),
- selectInput("CC","Please select a course", choices = c("E"=1,"M"=2)),
- selectInput("SP","Bla Bla", choices = c("AA"=1,"BB"=2,"CC"=3,"DD"=4,"EE"=5)),
- numericInput("UT",label = "Available", value = 10, min = 10),
- actionButton("RM", label = "RM",style="width:32%;"),
- actionButton("Cont", label = "Cont",style="width:32%;"),
- hidden(actionButton("strt", label = "Start",style="width:32%;")),
- actionButton("logout", "Logout",style="color: red; width:32%;")
- ),
- mainPanel(tableOutput('path'),
- shinyjs::useShinyjs(),
- hidden(actionButton("nxt", label = "Done/Next",style="color: blue;width:15%;float:right")),
- hidden(selectInput("test", "Was it easy?", list(" "="","No" = "No", "Not_sure" = "Not sure", "Yes" = "Yes"),selected = NULL))
- )
- )
- )
- }
- server = (function(input, output,session) {
- USER <- reactiveValues(Logged = Logged)
- observe({
- if (USER$Logged == FALSE) {
- if (!is.null(input$Login)) {
- if (input$Login > 0) {
- Username <- isolate(input$userName)
- Password <- isolate(input$passwd)
- query <- sprintf({"
- SELECT rowid
- FROM users
- WHERE username='%s' and password ='%s'"},
- Username, Password, serialize=F)
- db <- RSQLite::dbConnect(RSQLite::SQLite(), dbname="db.sqlite")
- user <- RSQLite::dbGetQuery(db, query)
- RSQLite::dbDisconnect(db)
- if ( length(user$rowid)==1 ) {
- USER$Logged <- TRUE
- }
- }
- }
- }
- })
- observe({
- if (USER$Logged == FALSE) {
- output$page <- renderUI({div(class="outer",do.call(bootstrapPage,c("",ui1())))})
- }
- if (USER$Logged == TRUE)
- {
- output$page <- renderUI({div(class="outer",do.call(navbarPage,c(inverse=TRUE,title = paste("Welcome", isolate(input$userName)," !"),ui2())))})
- shinyjs::hide("nxt")
- shinyjs::hide("test")
- print(ui)
- }
- })
- })
- ui = (htmlOutput("page"))
- library(shiny)
- library(RSQLite)
- db <- dbConnect(SQLite(), dbname="db.sqlite")
- dbSendQuery(conn = db,"CREATE TABLE users (username TEXT, password TEXT, email TEXT)")
- dbSendQuery(db, "INSERT INTO users ( username, password, email) VALUES ( 'ester', 'silva', 'abc@gmail.com');")
Add Comment
Please, Sign In to add comment