简体   繁体   English

闪亮的应用程序(使用shinydashboard):登录后页面变得奇怪

[英]Shiny App (using shinydashboard) : page goes weird after login

I create a shiny application but I want users to login to access the application. 我创建了一个闪亮的应用程序,但是我希望用户登录才能访问该应用程序。 Then I find a way to create the login page by this: Starting Shiny app after password input . 然后,我找到一种通过以下方法创建登录页面的方法: 输入密码后启动Shiny应用程序 But I have a problem that my APP using the package "shinydashboard", and after login the page goes weird. 但是我有一个问题,我的APP使用软件包“ shinydashboard”,并且登录后页面变得很奇怪。 I'm not familiar with HTML things. 我对HTML东西不熟悉。 Does any one knows how to fix this problem? 有谁知道如何解决此问题? Codes are below: 代码如下:

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))

After login the page should be like this: enter image description here 登录后页面应如下所示: 在此处输入图片描述

Not like this: enter image description here 不是这样的: 在此处输入图片描述

The navbarPage function expect the title as the first argument, since you have only two arguments and one argument is already identified, the navbarPage takes the ui2() function as the title. navbarPage函数将title作为第一个参数,因为您只有两个参数并且已经标识了一个参数,因此navbarPageui2()函数作为标题。

Just change 只是改变

div(class="outer",do.call(navbarPage,c(inverse=TRUE,ui2())))

with

div(class="outer",do.call(navbarPage,c(title = "MY Web APP", inverse=TRUE,ui2())))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM