我創建了一個閃亮的應用程序,但我希望用戶登錄以訪問應用程序。然後我找到一個方法來創建登錄頁面: Starting Shiny app after password input。但我有一個問題,我的APP使用軟件包「shinydashboard」,登錄後頁面變得很奇怪。我不熟悉HTML的東西。有誰知道如何解決這個問題? 代碼如下:閃亮的應用程序(使用shinydashboard):登錄後頁面變得奇怪
library(shiny)
library(shinydashboard)
Logged = FALSE;
my_username <- "test"
my_password <- "test"
ui1 <- function(){
tagList(
div(id = "login",
wellPanel(textInput("userName", "Username"),
passwordInput("passwd", "Password"),
br(),actionButton("Login", "Log in"))),
tags$style(type="text/css", "#login {font-size:10px; text-align: left;position:absolute;top: 40%;left: 50%;margin-top: -100px;margin-left: -150px;}")
)}
ui2 <- function(){
tagList(
dashboardPage(
dashboardHeader(title = "MY Web APP"),
dashboardSidebar(
sidebarMenu(
menuItem("menu1", tabName = "menu1", icon = icon("bank"),
badgeColor = "blue"),
menuItem("menu2", tabName = "menu2", icon = icon("bar-chart"))
)),
dashboardBody(
tabItems(
# First tab content
tabItem(tabName = "menu1",
fluidRow(
sidebarLayout(
sidebarPanel(
selectInput("pet1","PET:",c("dog","cat","pig"),selected = "dog"),
fileInput(inputId = "iFile", label = "Upload Excel:",
accept="application/vnd.ms-excel"),
actionButton("go","Go!"),
downloadButton('downloadData', 'Download')
),
# Show a plot of the generated distribution
mainPanel(
tabsetPanel(
tabPanel("summary", tableOutput("summary1")),
tabPanel("Curve", plotlyOutput("curve1"))
)
)
)
)
),
# Second tab content
tabItem(tabName = "menu2",
fluidRow(
sidebarLayout(
sidebarPanel(
selectInput("pet1","PET:",c("dog","cat","pig"),selected = "dog"),
fileInput(inputId = "iFile", label = "Upload Excel:",
accept="application/vnd.ms-excel"),
actionButton("go","Go!"),
downloadButton('downloadData', 'Download')
),
# Show a plot of the generated distribution
mainPanel(
tabsetPanel(
tabPanel("summary", tableOutput("summary1")),
tabPanel("Curve", plotlyOutput("curve1"))
)
)
)
)
)
)
),
skin = "purple"
)
)
}
ui = (htmlOutput("page"))
server = (function(input, output,session) {
USER <- reactiveValues(Logged = Logged)
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
}
}
}
}
}
})
observe({
if (USER$Logged == FALSE) {
output$page <- renderUI({
div(class="outer",do.call(bootstrapPage,c("",ui1())))
})
}
if (USER$Logged == TRUE)
{
output$page <- renderUI({
div(class="outer",do.call(navbarPage,c(inverse=TRUE,ui2())))
})
}
})
})
runApp(list(ui = ui, server = server))
登錄後的頁面應該是這樣的: enter image description here
不喜歡這樣的: enter image description here
謝謝你很多。它可以工作,但頁面的顏色仍然不像我上傳的第一張圖片。你知道爲什麼嗎? – ghoost2010
問題是,使用該方法加載儀表板頁面時,主體沒有'class =「skin-purple」'屬性。你應該考慮使用不同的登錄選項。 – Geovany
關於使用其他登錄選項,您有任何建議嗎? – ghoost2010