R Shiny: user authentication for a single app.R

前端 未结 7 1484
孤城傲影
孤城傲影 2020-12-25 14:15

I am developing a R Shiny App and want to add user name and logins. I checked the RStudio demo but that is only using the ShinyServer Pro and I am using the mongolite packag

7条回答
  •  春和景丽
    2020-12-25 15:12

    I use shinyAppLogin instead of shinApp:

    # R code
    shinyAppLogin <- function( ui, server, title="Restricted Area", accounts = list(admin="admin"), ...) {
        ui_with_login <- bootstrapPage(theme = "login_style.css",
            div(class="login-page",
                div(class="form",
                    h1(title), br(),
                    tags$form(class="login-form",
                        textInput(inputId = "user", label = NULL, placeholder="Username"),
                        passwordInput(inputId = "pass", label = "", placeholder = "Password" ),
                        actionButton(inputId = "login", label = "Login")
                ) ) ) )
    
        server_with_login <- function(input, output, session) {
    
            observeEvent(input$login, ignoreNULL = T, {
    
            if ( input$user %in% names(accounts) && input$pass == accounts[[input$user]] ) {
    
                removeUI(selector = "body", multiple = T, immediate = T, session = session)
                insertUI(selector = "html", where = "beforeEnd", ui = ui, immediate = T, session = session )
                server(session$input, session$output, session = session)
            }
        } ) }
    
        shinyApp(ui = ui_with_login, server = server_with_login, ...)
    }
    

    then my code becomes: shinyAppLogin(my_ui, my_server)

    Login screen when styles

    then I used css from enter link description here just save your css in www/login_style.css

提交回复
热议问题