【发布时间】:2018-06-14 06:18:03
【问题描述】:
我想构建一个应用程序,并且某些选项卡将对用户隐藏,直到他输入正确的密码。我知道如何使用shinyjs::hideTab:
library(shiny);library(shinyjs)
ui <- fluidPage(useShinyjs(),
navbarPage("hello", id="hello",
tabPanel("home", br(), h3("this is home"),passwordInput("pass", "enter 'password' to see the tabs: "),actionButton("enter", "enter")),
tabPanel("tab2", br(), h4("this is tab2")),
tabPanel("tab3 with a lot of stuff in it", br(), h4("this is tab3"))))
server <- function(input, output, session) {
hideTab("hello", "tab2"); hideTab("hello", "tab3 with a lot of stuff in it")
observeEvent(input$enter, {
if (input$pass == "password"){showTab("hello", "tab2"); showTab("hello", "tab3 with a lot of stuff in it")}})}
shinyApp(ui, server)
不过有一点“东西”。在我的应用程序中,隐藏的选项卡有很多东西,如小部件、uiOutputs、绘图、图像、global.R 中的文件读取等。结果是加载时间更长,并且在应用程序的这段加载时间内(之前hideTab 指令运行)用户实际上看到了隐藏的选项卡,甚至可以单击它们并查看里面的内容。它们会保持“可见”状态大约 1 秒钟,然后隐藏起来。
有没有办法在 UI 构建之前立即隐藏它们?我更喜欢一个解决方案,而不必将我所有的 ui 代码都放入 server.R 脚本中......
谢谢
【问题讨论】:
-
不幸的是,看起来没有一个很好的解决方案 (github.com/daattali/shinyjs/issues/43)。正如问题中提到的,一个想法可能是使用 CSS,但这可能比它的价值更多的努力
-
@MikeH。这里只是对程序的评论:在输入密码之前隐藏选项卡是非常不安全的。
style="display: none;"可以简单地由用户通过在每个常用浏览器中单击右键来删除。在用户输入正确密码后,使用appendTab创建选项卡可能会更好。
标签: javascript r shiny hide shinyjs