Shiny: How to detect which accordion elements is selected?

前端 未结 1 2025
傲寒
傲寒 2021-01-16 06:15

I have an R Shiny where server.R outputs a large number of dynamically generated UI objects.

Rather than process hundreds of objects in input

1条回答
  •  执念已碎
    2021-01-16 06:25

    I'd suggest setting a dummy input that will hold the current value (or in this case, text) of the selected tab.

    This might help you:

    library(shiny)
    library(bsplus)
    
    shinyApp(
      ui = fluidPage(
        tags$script("$(function() {
                      $('#meet_the_beatles a').on('click', function(x) {
                        Shiny.onInputChange('selected_tab', x.target.innerText)
                      });
                    });"),
    
        fluidRow(
          column(
            width = 6,
            offset = 3,
            bs_accordion(id = "meet_the_beatles") %>%
              bs_append(title = "John", content = "Rhythm guitar, vocals") %>%
              bs_append(title = "Paul", content = "Bass guitar, vocals") %>%
              bs_append(title = "George", content = "Lead guitar, vocals") %>%
              bs_append(title = "Ringo", content = "Drums, vocals")
          )
        ),
    
        HTML("

    0 讨论(0)
提交回复
热议问题