【发布时间】:2019-11-07 17:53:58
【问题描述】:
我可以使用this 问题呈现可排序的 menuSubItems 列表,但我想跟踪它们在排序后的顺序。 menuSubItems 不会出现在服务器端的input 中(至少不是整个列表),我希望能够有办法访问@987654324 中值列表的顺序@ 无需深入研究在 Shiny 中创建自定义输入绑定。
任何创意都将不胜感激!
library(shiny)
library(shinydashboard)
library(sortable)
# Define UI for shinydashboard
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(
menuItem("tab_one", tabName = "test_body"),
menuItemOutput("test")
)
),
dashboardBody(
tabItem("test_body", actionButton("click_me", "Click Me"))
)
)
# Define server logic to dynamically create menuSubItems
server <- function(input, output) {
observeEvent(input$click_me, {
tabs_list <- lapply(1:5, function(x) {
menuSubItem(text = paste("tab", x))
})
output$test <- renderMenu({
menu <- menuItem("test_tabs", do.call(tagList, tabs_list))
menu$children[[2]] <- tagAppendAttributes(menu$children[[2]], id = "test_tabs")
tagAppendChildren(menu, sortable_js("test_tabs"))
})
})
}
# Run the application
shinyApp(ui = ui, server = server)
【问题讨论】:
标签: r shiny shinydashboard sortablejs