【发布时间】:2021-05-04 13:20:05
【问题描述】:
我希望 shinydashboard 中的导航 menuItem 是有条件的,并根据 server.R 中评估的条件显示。
为此,我在ui.R 中的常规sidebarMenu 旁边定义了一个conditionalPanel 包含一个menuItem(我使用shinymanager 来验证用户身份):
sidebar <- dashboardSidebar(
width=280,
sidebarMenu(id = "sidebarmenu",
menuItem(...),
menuItem(...,
menuSubItem(...),
menuSubItem(...)
)
),
conditionalPanel(condition = "output.x === 1",
menuItem("title", tabName="tabname")
)
)
body <- dashboardBody(
tabItems(
tabItem(tabName = "id",
fluidPage(
titlePanel("Hello World")
)),
tabItem(tabName="tabname",
titlePanel("mytitle"),
fluidPage(
dataTableOutput(outputId = "table")
)
)
)
ui <- dashboardPage(
dashboardHeader(title = "Hello App", titleWidth=280),
sidebar,
body
)
ui <- secure_app(ui)
在server.R,我根据登录用户的登录信息切换output.x:
server <- function(input, output, session) {
# login logic: call the server part, check_credentials returns a function to
# authenticate users
res_auth = secure_server(
check_credentials = check_credentials
)
# Define the logon details with a reactive variable
auth_output <- reactive({
reactiveValuesToList(res_auth)
})
output$x = reactive({
auth_output()$role
})
# Generate a data table from the DB to show conditionally
conn = ...
data = load_data(conn, ...)
disconnect(conn)
output$table = dt_render({data})
# All output variables that need to be transferred to the UI should have
# suspendWhenHidden = FALSE:
outputOptions(output, "x", suspendWhenHidden = FALSE)
问题:条件表只显示一次,只要我愿意。这一次之后,一旦我离开它,点击条件menuItem 不会显示任何内容。 menuItem 仍然出现,这意味着 output.x === 1 被正确评估,但其内容,即随后的 tabItem,仍然隐藏。
我已经尝试将isolate 分配给output.x,甚至将其固定为1 无济于事。有线索吗?
【问题讨论】:
标签: r shiny shinydashboard