R语言 移动使用身份验证的闪亮应用程序的注销按钮

lx0bsm1f  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(95)

我有一个简单的闪亮的应用程序,使用身份验证方法。我想知道是否有可能将“注销”按钮从其当前位置内的侧边栏。事情是,我希望我的侧边栏被隐藏,以及在用户登录之前,我使用req(credentials()$user_auth)之前,它这样做。事实上,注销按钮根本没有显示。用户名和密码是“user1”、“pass1”。

#app.r
library(shiny)
library(shinyauthr)
library(shinyjs)

# dataframe that holds usernames, passwords and other user data
user_base <- data.frame(
  user = c("user1", "user2"),
  password = c("pass1", "pass2"), 
  permissions = c("admin", "standard"),
  name = c("User One", "User Two"),
  stringsAsFactors = FALSE,
  row.names = NULL
)

ui <- fluidPage(
  # must turn shinyjs on
  shinyjs::useShinyjs(),

  # add login panel UI function
  shinyauthr::loginUI(id = "login"),
  # setup table output to show user info after login
  sidebarLayout(
    uiOutput("menu"),
    mainPanel(
      tableOutput("user_table")
    )
  )

)

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

  # call the logout module with reactive trigger to hide/show
  logout_init <- callModule(shinyauthr::logout, 
                            id = "logout", 
                            active = reactive(credentials()$user_auth))

  # call login module supplying data frame, user and password cols
  # and reactive trigger
  credentials <- callModule(shinyauthr::login, 
                            id = "login", 
                            data = user_base,
                            user_col = user,
                            pwd_col = password,
                            log_out = reactive(logout_init()))

  # pulls out the user information returned from login module
  user_data <- reactive({credentials()$info})

  output$menu<-renderUI({
    req(credentials()$user_auth)
    sidebarPanel(
      # add logout button UI 
      div( shinyauthr::logoutUI(id = "logout"))
    )

  })

  output$user_table <- renderTable({
    # use req to only render results when credentials()$user_auth is TRUE
    req(credentials()$user_auth)
    user_data()
  })
}

shinyApp(ui = ui, server = server)

字符串

muk1a3rh

muk1a3rh1#

删除pull-right类并将UI移动到sidebarPanel

ui <- fluidPage(
  # must turn shinyjs on
  shinyjs::useShinyjs(),
  # add logout button UI 
  # add login panel UI function
  shinyauthr::loginUI(id = "login"),
  # setup table output to show user info after login
  sidebarLayout(
    sidebarPanel(div(shinyauthr::logoutUI(id = "logout"))), # UI moved here
    mainPanel(
      tableOutput("user_table")
    )
  )

)

字符串

相关问题