0

我编写了一个带有来自 bs4Dash 的可排序框的小型模块化闪亮应用程序,但是,我无法像在https://dgranjon.shinyapps.io/bs4DashDemo/的在线演示中那样拖动这些框(可排序) 。我认为我的模块存在命名空间问题,但我不知道在哪里。请问有什么帮助吗?

最终目标(针对上下文)是可排序的框,可以通过按钮添加和删除新框(稍后我将包含更多代码,以通过会话之间的 csv 读取和写入注释)。我希望将它们四处移动以安排优先任务/笔记。

library(shiny)
library(bs4Dash)

sortcard_UI <- function(id) {
  ns <- NS(id)
  tagList(
    uiOutput(ns("outpt_card_cntrl"))
  )
}

sortcard <- function(input, output, session) {
  
  output$outpt_card_cntrl <- renderUI({
    
    ns <- session$ns
    box_id = environment(ns)[['namespace']]
    tags$div(id = box_id,
             tagList(
               sortable(width = 11,
                        box(title = paste0("Box No: ", box_id), 
                            width = 12,
                            textAreaInput(ns("add_text"), label = NULL, placeholder = "Add notes"))),
               column(1, actionButton(ns('deleteButton'), '',
                                      icon = shiny::icon('times'),
                                      style = 'float: right')))
    )
  })
}

ui = dashboardPage(
  options = NULL,
  header = dashboardHeader(),
  sidebar = dashboardSidebar(),
  body = dashboardBody(
    tabItem(
      tabName = "sortablecards",
      fluidRow(actionButton('addButton', '', icon = icon('plus'))))
  ),
  controlbar = dashboardControlbar(),
  title = ""
)

server <- function(input, output, session) {
  
  remove_shiny_inputs <- function(id, .input) {
    invisible(
      lapply(grep(id, names(.input), value = TRUE), function(i) {
        .subset2(.input, "impl")$.values$remove(i)
      })
    )
  }
  
  observeEvent(input$addButton, {
    
    i <- sprintf('%04d', input$addButton)
    id <- sprintf('srtcrd%s', i)
    
    insertUI(
      selector = '#addButton',
      where = "beforeBegin",
      ui = sortcard_UI(id)
    )
    
    callModule(sortcard, id)
    observeEvent(input[[paste0(id, '-deleteButton')]], {
      removeUI(selector = sprintf('#%s', id))
      remove_shiny_inputs(id, input)
    })
  })
}

shinyApp(ui, server)
4

0 回答 0