我的问题类似于Shiny how to block the user from accessing a tab?
但我需要的是:
library(shiny)
ui <- shinyUI(navbarPage(
"",
tabPanel(
h1("Tab1"),
value = "nav1",
mainPanel(
br(),
h2("The user must press this button to access the other tab."),
br(),
shiny::actionButton('button', 'press the button', onclick = "$(tab).removeClass('disabled')")
)
),
tabPanel(
h1("Tab2"),
value = "nav2",
uiOutput("tab2contents")
),
tags$script(
'
var tab = $(\'a[data-value="nav2"]\').parent().addClass("disabled");
$(function(){
$(tab.parent()).on("click", "li.disabled", function(e) {
e.preventDefault();
return false;
});
});
'
)
))
server <- shinyServer(function(input, output) {
})
# Run the application
shinyApp(ui = ui, server = server)
在上面的代码中,除非单击按钮,否则第二个选项卡将被阻止,但如何进一步更新此选项卡,以便在单击按钮后,用户将自动转到第二个选项卡?