我希望在闪亮的仪表板中有不同的页面.首先,我创建了一个登录页面,为用户和管理员提供身份验证.之后,如果管理员登录系统想要查看用户无法访问它们的一些选项.问题:当我以用户或管理员身份登录时,我可以在后台看到主要的ui.r页面如何解决此问题,只能看到admin.R或user.R?当用户登录仪表板时显示,当管理员登录时,仪表板和小部件显示.所以我决定在R中创建4个页面如下:ui.R
library(shiny)
library(shinydashboard)
shinyUI(
dashboardPage(
dashboardHeader(title = "Navigational Support System"),
dashboardSidebar(),
dashboardBody(
box(
uiOutput("page")
)
)
)
)
Run Code Online (Sandbox Code Playgroud)
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 …Run Code Online (Sandbox Code Playgroud) 我是闪亮的新手。当我制作我的项目时,我需要在服务器端隐藏dashboardHeader。
在 Shinydashboard 网站上,我找到了代码dashboardHeader(disable = TRUE)。我试过这个,但它不起作用。
但是,我尝试使用shinyjs 来解决问题。
<code>
library(shiny)
library(shinydashboard)
library(shinyjs)
ui <- dashboardPage(
dashboardHeader(
extendShinyjs(text = 'shinyjs.hidehead = function(params) {
$("header").addClass("sidebar-collapse") }'),
),
dashboardSidebar(),
dashboardBody(
actionButton("button","hide_header",width = 4 )
)
)
server <- function(input, output) {
observeEvent(input$button, {
js$hidehead()
})}
shinyApp(ui, server)</code>
Run Code Online (Sandbox Code Playgroud)
我想你已经知道了,它仍然没有奏效。
对我的情况有什么想法吗?