I want to have different pages in my shiny panel. First of all, I created a login page to give authentication to the user and administrator. After that, if the login administrator wants to see some parameters that the user cannot get to them. Question: when I log in as a user or administrator, I see the main ui.r page in the background, how can I fix this problem to see only admin.R or user.R? When the user logs into the dashboard, and when the administrator logs in, it is displayed on the panel and widgets. So I decided to create 4 pages in R as follows: ui.R
library(shiny) library(shinydashboard) shinyUI( dashboardPage( dashboardHeader(title = "Navigational Support System"), dashboardSidebar(), dashboardBody( box( uiOutput("page") ) ) ) )
server.R
library(shiny) library(shinydashboard) source("user.R") source("admin.R") ############################################################################################################ #Login USER and ADMIN TO the System my_username <- c("test","admin") my_password <- c("test","123") get_role=function(user){ if(user=="test") { return("TEST") }else{ return("ADMIN") } } get_ui=function(role){ if(role=="TEST"){ return(list_field_user) }else{ return(list_field_admin) } } shinyServer(function(input, output,session) { USER <- reactiveValues(Logged = FALSE,role=NULL) ui1 <- function(){ tagList( div(id = "login", wellPanel(textInput("userName", "Username"), passwordInput("passwd", "Password"), br(),actionButton("Login", "Log in"))) #tags$style(type="text/css", '#login{ width:750px; float:left;}') )} ui2 <- function(){tagList(tabPanel("NSS",get_ui(USER$role)))} observe({ if (USER$Logged == FALSE) { if (!is.null(input$Login)) { if (input$Login > 0) { Username <- isolate(input$userName) Password <- isolate(input$passwd) Id.username <- which(my_username == Username) Id.password <- which(my_password == Password) if (length(Id.username) > 0 & length(Id.password) > 0) { if (Id.username == Id.password) { USER$Logged <- TRUE USER$role=get_role(Username) } } } } } }) observe({ if (USER$Logged == FALSE) { output$page <- renderUI({ div(class="outer",do.call(bootstrapPage,c("Please Login",ui1()))) }) } if (USER$Logged == TRUE) { output$page <- renderUI({ div(class="outer",do.call(navbarPage,c(inverse=TRUE,title = "Welcome Admin!",ui2()))) }) #print(ui) } }) ################################################################################################## })
admin.r
list_field_admin = shinyUI( dashboardPage( dashboardHeader(title = "Decison Support System"), dashboardSidebar( sidebarMenu( menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")), menuItem("Widgets", tabName = "widgets", icon = icon("th")) ) ), dashboardBody( ) ))
user.r
list_field_user = shinyUI( dashboardPage( dashboardHeader(title = "Decison Support System"), dashboardSidebar( sidebarMenu( menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")) ) ), dashboardBody( ) ))