Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

257
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda