Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

262
Visualizações
Brillante, ¿cómo bloquear al usuario para que no acceda a una pestaña?

Necesito bloquear el acceso del usuario a otras pestañas hasta que se cumplan ciertas acciones. En este ejemplo reproducible, quiero bloquear al usuario para acceder a la Tab 2 hasta que presione el botón.

Así es como se ve la aplicación:

ingrese la descripción de la imagen aquí

Aquí está el código de la aplicación:

 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') ) ), tabPanel(h1("Tab2"), value = "nav2", h3('Block access until user presses button') ) ) ) server <- shinyServer(function(input, output) { }) # Run the application shinyApp(ui = ui, server = server)

Me gustaría que el usuario pueda ver que Tab2 existe, pero que no se pueda hacer clic hasta que presione el botón.

¿Algunas ideas?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

  1. No hay necesidad de usar ningún procesamiento del lado del servidor. Uno de los conceptos modernos de desarrollo de aplicaciones web es la separación de front-end y back-end. Si puede hacerlo en el front-end, entonces no use el servidor para hacer el trabajo.
  2. conditionalPanel es una solución mejor, pero los usuarios aún pueden hacer clic en el botón de la pestaña, solo darles una página vacía.

Aquí hay una solución aún mejor, usemos algunos js para deshabilitar el botón de pestaña a menos que los usuarios hagan clic en el botón de acción. Los usuarios pueden ver el botón de la pestaña, pero está gris y no se puede hacer clic en el inicio:

 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)

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza Relatório

0

Utilice conditionalPanel() . ¿Condición? El botón no debe tener cero clics.

Su ejemplo ahora se convierte en:

 library(shiny) ui <- shinyUI( navbarPage( title = "", tabPanel( title = 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') ) ), tabPanel( h1("Tab2"), value = "nav2", # ----conditional panel here---- conditionalPanel( condition = "input.button != 0", h3('Block access until user presses button') ) ) ) ) server <- shinyServer(function(input, output) { }) # Run the application shinyApp(ui = ui, server = server)
about 4 years ago · Juan Pablo Isaza Relatório

0

Agregando detalles a mi comentario anterior:

 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') ) ), tabPanel( h1("Tab2"), value = "nav2", uiOutput("tab2contents") ) ) ) server <- shinyServer(function(input, output) { v <- reactiveValues(tab2Active=FALSE) observeEvent(input$button, { v$tab2Active <- TRUE}) output$tab2contents <- renderUI({ if (v$tab2Active) { h3('Tab 2 is active') } else { h3('Block access until user presses button') } }) }) # Run the application shinyApp(ui = ui, server = server)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda