验证后 R shinymanager removeTab
R shinymanager removeTab after authentication
我想隐藏“登录”选项卡面板,并在用户能够通过身份验证进入应用后呈现“内容”选项卡面板的内容。
确实呈现了“内容”选项卡面板的内容,但没有删除“登录”选项卡面板。我不明白为什么会这样。
这里是重现问题的代码:
library(shiny)
library(shinymanager)
# Credentials
credentials <- data.frame(
user = c("test"),
password = c(scrypt::hashPassword("test")),
is_hashed_password = TRUE
)
ui <- navbarPage(
"Test project",
id="main",
tabPanel(
"Login",
auth_ui(
id="auth",
lan=use_language("fr")
)
),
tabPanel(
"Content",
uiOutput("test")
)
)
server <- function(input, output){
auth <- callModule(
module = auth_server,
id = "auth",
check_credentials = check_credentials(credentials)
)
reactive({
req(auth$result)
removeTab(
inputId = "main",
target = "Login"
)
})
output$test <- renderUI({
req(auth$result)
tags$h1("Test")
})
}
shinyApp(ui=ui, server=server)
提前致谢:)
不要单独使用reactive
,而是放入observer
,因为反应式表达式需要被某些东西调用或被另一个表达式调用,否则它不会被执行:
observe({
req(auth$result)
removeTab(
inputId = "main",
target = "Login"
)
})
我想隐藏“登录”选项卡面板,并在用户能够通过身份验证进入应用后呈现“内容”选项卡面板的内容。
确实呈现了“内容”选项卡面板的内容,但没有删除“登录”选项卡面板。我不明白为什么会这样。
这里是重现问题的代码:
library(shiny)
library(shinymanager)
# Credentials
credentials <- data.frame(
user = c("test"),
password = c(scrypt::hashPassword("test")),
is_hashed_password = TRUE
)
ui <- navbarPage(
"Test project",
id="main",
tabPanel(
"Login",
auth_ui(
id="auth",
lan=use_language("fr")
)
),
tabPanel(
"Content",
uiOutput("test")
)
)
server <- function(input, output){
auth <- callModule(
module = auth_server,
id = "auth",
check_credentials = check_credentials(credentials)
)
reactive({
req(auth$result)
removeTab(
inputId = "main",
target = "Login"
)
})
output$test <- renderUI({
req(auth$result)
tags$h1("Test")
})
}
shinyApp(ui=ui, server=server)
提前致谢:)
不要单独使用reactive
,而是放入observer
,因为反应式表达式需要被某些东西调用或被另一个表达式调用,否则它不会被执行:
observe({
req(auth$result)
removeTab(
inputId = "main",
target = "Login"
)
})