почему эти stati c и dynamici c bs_accordion ведут себя по-разному в этом блестящем приложении? - PullRequest
0 голосов
/ 31 января 2020

Я не понимаю, почему эти stati c и dynamic c bs_accordion ведут себя по-разному в этом блестящем приложении?

если кто-то знает, как динамически создать bs_accordion, он, вероятно, спасет мой уик-энд!

Спасибо; -)

блестящее приложение ниже создает статус c bs_accordion и динамический c bs_accordion, но, как вы можете видеть, динамический c bs_accordion не может быть рухнул при нажатии. Почему ? Может кто-нибудь помочь мне это исправить?

library(shiny)
library(bsplus)
library(shinyjs)

# global button counter 
cpt <- 0

# function to create a new slider input
newinput <- function(ID, tag){ 
  div(id=ID,
      bs_append(
        tag = tag,
        title_side = paste0("dynamic",ID),
        content_side = NULL,
        content_main = sliderInput( inputId = paste0("dynamic_slider_",ID),
                                    label = paste0("dynamic_slider_",ID),
                                    value = 0,
                                    min=0,
                                    max=10)
      )
  )
}

ui <- shinyUI(fluidPage(
  titlePanel("static bs_accordion_sidebar"),
  bs_accordion_sidebar(id = "static_accordion",
                       spec_side = c(width = 4, offset = 0),
                       spec_main = c(width = 8, offset = 0)) %>% 
    bs_append(
      title_side = "static1",
      content_side = NULL,
      content_main = sliderInput( inputId = "static_slider_1",
                                  label = "static_slider_1",
                                  value = 0,
                                  min=0,
                                  max=10)) %>% 
    bs_append(
      title_side = "static2",
      content_side = NULL,
      content_main = sliderInput( inputId = "static_slider_2",
      label = "static_slider_2",
      value = 0,
      min=0,
      max=10)),
  titlePanel("dynamic bs_accordion_sidebar"),
  fluidRow(
      actionButton("add", "+"),
      mytag <- bs_accordion_sidebar(id = "dynamic_accordion",
                                    spec_side = c(width = 4, offset = 0),
                                    spec_main = c(width = 8, offset = 0)),
      div(id = "placeholder"),
      actionButton("delete", "-")
  ),
  useShinyjs(debug = TRUE),
  use_bs_accordion_sidebar() 
))

server <- shinyServer(function(input, output) {
  observeEvent(input$add, {
    cpt <<- cpt + 1 
    insertUI(
      selector ='#placeholder',
      where = "beforeEnd",
      ui = newinput(ID = cpt, tag = mytag)
    )
  })

  observeEvent(input$delete, {
    removeUI(selector = paste0('#', cpt))
    runjs(paste0('Shiny.onInputChange("dynamic_slider_',cpt,'", null)'))
    cpt <<- cpt - 1
  })
})
shinyApp(ui, server)
...