How to add authentication,login logout on shinyapps deployed on shinyapps.io.Also tell me how to download file from shiny app

427 views
Skip to first unread message

R R

unread,
Jul 25, 2018, 7:35:16 AM7/25/18
to shinyapps.io Users
I have developed one app and have login button on that.
ui.r

# Add custom CSS & Javascript;
tagList(
tags$head(
tags$link(rel="stylesheet", type="text/css",href="style.css"),
tags$script(type="text/javascript", src = "md5.js"),
tags$script(type="text/javascript", src = "passwdInputBinding.js")
)
),

## Login module;
div(class = "login",
uiOutput("uiLogin"),
textOutput("pass")
),

div(class = "span4", uiOutput("obs")),
div(class = "span8", plotOutput("distPlot"))

))
shinyUI(bootstrapPage(


server.r
library(datasets)
Logged = FALSE;
PASSWORD <- data.frame(Brukernavn = "withr", Passord = "25d55ad283aa400af464c76d713c07ad")
# Define server logic required to summarize and view the selected dataset
shinyServer(function(input, output) {
source("www/Login.R", local = TRUE)

observe({
if (USER$Logged == TRUE) {
output$obs <- renderUI({
sliderInput("obs", "Number of observations:",
min = 10000, max = 90000,
value = 50000, step = 10000)
})

output$distPlot <- renderPlot({
dist <- NULL
dist <- rnorm(input$obs)
hist(dist, breaks = 100, main = paste("Your password:", input$passwd))
})
}
})
})


www/login.r
USER <- reactiveValues(Logged = Logged)

passwdInput <- function(inputId, label) {
tagList(
tags$label(label),
tags$input(id = inputId, type="password", value="")
)
}

output$uiLogin <- renderUI({
if (USER$Logged == FALSE) {
wellPanel(
textInput("userName", "User Name:"),
passwdInput("passwd", "Pass word:"),
br(),
actionButton("Login", "Log in")
)
}
})

output$pass <- renderText({
if (USER$Logged == FALSE) {
if (!is.null(input$Login)) {
if (input$Login > 0) {
Username <- isolate(input$userName)
Password <- isolate(input$passwd)
Id.username <- which(PASSWORD$Brukernavn == Username)
Id.password <- which(PASSWORD$Passord == Password)
if (length(Id.username) > 0 & length(Id.password) > 0) {
if (Id.username == Id.password) {
USER$Logged <- TRUE
}
} else {
"User name or password failed!"
}
}
}
}
})

How do i add logout button on navbar menu after log  in
I referred the code from above link
https://gist.github.com/withr/9001831
#### Log in module ###


Joshua Spiewak

unread,
Jul 25, 2018, 9:46:46 AM7/25/18
to shinyapps.io Users
This sounds like a general question about Shiny and you will reach a broader audience by asking in the Shiny Community.

This group is focused on hosting Shiny applications on shinyapps.io, which offers built-in authentication at the Standard and higher tier.
Reply all
Reply to author
Forward
0 new messages