[R] R help needed

Sana Fatima s.sana.f at gmail.com
Thu Jun 23 16:50:26 CEST 2016


 Hello everyone,
I am trying to create an shiny app that could be used for ~ 700 different
user names and passwords. Each username and password would lead to a
different set of data being pulled in, however the tabs and fields with in
the app will be the same. Just that different username would display
different data.I have the basic app running but would appreciate help with
the program for the login/password part.

I have tried incorporating the example code(
http://shiny.rstudio.com/articles/permissions.html) to my program ( see
portion of my code below). However, when I ran the app, it gives me a blank
screen for this tab. This is because the user = NULL but i don't get an
option to enter the username and password information. Where and how do we
get the login form at the beginning of the application? Is there a way to
have the login in form and the application linked together so that when the
application is run it automatically takes u to the login page where user
can enter their info and see the info accordingly. Would really appreciate
your help on this. Thanks in advance

server <- function(input, output, session) {

user <- reactive({
session$user
})


table <- formattable(tab1, list(
"NumberServed" = formatter(
"span",
style = x ~ style(color = ifelse(x<tab1$NumberServed_prev,'red',
ifelse(x>tab1$NumberServed_prev,'green','orange')), font.weight = "bold"),
x ~ icontext(ifelse(x < tab1$NumberServed_pr_goal,
"arrow-down",ifelse(x>tab1$NumberServed_pr_goal,'arrow-up','')),x)),
"NumberExited" = formatter(
"span",
style = x ~ style(color = ifelse(x<tab1$NumberExited_prev,'red',
ifelse(x>tab1$NumberExited_prev,'green','orange')), font.weight = "bold"),
x ~ icontext(ifelse(x < tab1$NumberExited_pr_goal,
"arrow-down",ifelse(x>tab1$NumberExited_pr_goal,'arrow-up','')),x)),

"PercentWithBarriers" = formatter(
"span",
style = x ~ style(color = ifelse(x<tab1$PercentWithBarriers_prev,'red',
ifelse(x>tab1$PercentWithBarriers_prev,'green','orange')), font.weight =
"bold"),
x ~ icontext(ifelse(x < tab1$PercentWithBarriers_pr_goal,
"arrow-down",ifelse(x>tab1$PercentWithBarriers_pr_goal,'arrow-up','')),x)),

"EmploymentQ2" = formatter(
"span",
style = x ~ style(color = ifelse(x<tab1$EmploymentQ2_prev,'red',
ifelse(x>tab1$EmploymentQ2_prev,'green','orange')), font.weight = "bold"),
x ~ icontext(ifelse(x < tab1$EmploymentQ2_pr_goal,
"arrow-down",ifelse(x>tab1$EmploymentQ2_pr_goal,'arrow-up','')),x)),

"EmploymentQ4" = formatter(
"span",
style = x ~ style(color = ifelse(x<tab1$EmploymentQ4_prev,'red',
ifelse(x>tab1$EmploymentQ4_prev,'green','orange')), font.weight = "bold"),
x ~ icontext(ifelse(x < tab1$EmploymentQ4_pr_goal,
"arrow-down",ifelse(x>tab1$EmploymentQ4_pr_goal,'arrow-up','')),x)),
"WagesQ2" = formatter(
"span",
style = x ~ style(color = ifelse(x<tab1$WagesQ2_prev,'red',
ifelse(x>tab1$WagesQ2_prev,'green','orange')), font.weight = "bold"),
x ~ icontext(ifelse(x < tab1$WagesQ2_pr_goal,
"arrow-down",ifelse(x>tab1$WagesQ2_pr_goal,'arrow-up','')),x)),
"CredentialRate" = formatter(
"span",
style = x ~ style(color = ifelse(x<tab1$CredentialRate_prev,'red',
ifelse(x>tab1$CredentialRate_prev,'green','orange')), font.weight = "bold"),
x ~ icontext(ifelse(x < tab1$CredentialRate_pr_goal,
"arrow-down",ifelse(x>tab1$CredentialRate_pr_goal,'arrow-up','')),x))

))

table$WagesQ2<-currency(table$WagesQ2,symbol = "$", digits = 0)
table$NumberServed<-accounting(table$NumberServed,digits=0)
table$NumberExited<-accounting(table$NumberExited,digits=0)
table$PercentWithBarriers<-percent(table$PercentWithBarriers,digits=2)
table$EmploymentQ2<-percent(table$EmploymentQ2,digits=2)
table$EmploymentQ4<-percent(table$EmploymentQ4,digits=2)
table$CredentialRate<-percent(table$CredentialRate,digits=2)
table$NumberServed_prev=NULL
table$NumberExited_prev=NULL
table$PercentWithBarriers_prev=NULL
table$EmploymentQ2_prev=NULL
table$EmploymentQ4_prev=NULL
table$WagesQ2_prev=NULL
table$CredentialRate_prev=NULL
table$NumberServed_pr_goal=NULL
table$NumberExited_pr_goal=NULL
table$PercentWithBarriers_pr_goal=NULL
table$EmploymentQ2_pr_goal=NULL
table$EmploymentQ4_pr_goal=NULL
table$WagesQ2_pr_goal=NULL
table$CredentialRate_pr_goal=NULL

myData <- reactive({
if (isManager()){
# If a manager, show everything.
return(table)
} else{
# If a regular salesperson, only show their own sales.
return(table[table$dist == user(),])
}
})


isManager <- reactive({
if (user() == "manager"){
return(TRUE)
} else{
return(FALSE)
}
})

output$results1 <- renderFormattable({
if(is.null(user())){return()}
myData()
})
)

}

-- 
Syeda Sana Fatima

	[[alternative HTML version deleted]]



More information about the R-help mailing list