【问题标题】:Multi level dropdown hover R shiny多级下拉悬停 R 闪亮
【发布时间】:2021-03-21 13:54:33
【问题描述】:

我正在为 R Shiny 中的多级下拉菜单寻找解决方案

我已经浏览了这里的大部分包,https://github.com/nanxstats/awesome-shiny-extensions 在任何可用的软件包中都找不到解决方案

一个接近的解决方案是

              # selectInput("state", "Choose a word:", width = 400,
                       #             list(`Building` = list("Apartment"="ap", "Bank"="bk", "Hospital"="hp"),
                       #                  `Nature` = list("Bank"="bk1", "River"="rv", "Orange"="or"),
                       #                  `Color` = list("Blue"="bl", "Orange"="or1", "Red"="rd"))

除非列表很长很难管理

附言问题和图片来自https://github.com/rstudio/shiny/issues/2729

【问题讨论】:

  • 这样的小部件应该做什么?当你点击一个项目时,你想要什么?
  • 见主帖中的例子
  • 复选框树不合适? See jsTreeR.
  • 并非如此。我需要当时选择一个。也不好看。
  • 没问题。您可以使用“jsTreeR”一次选择一个。

标签: r shiny htmlwidgets


【解决方案1】:

我刚刚做了一个包裹。它使用 JavaScript 库 jquery-contextMenu。要安装它:

remotes::install_github("stla/NestedMenu")

请注意,这只是目前的草稿。

使用示例:

library(NestedMenu)
library(shiny)

cities <- list(
  europe = list(
    name = "Europe",
    items = list(
      france = list(
        name = "France",
        items = list(
          paris = list(name = "Paris"),
          lyon = list(name = "Lyon")
        )
      ),
      italy = list(
        name = "Italy",
        items = list(
          roma = list(name = "Roma"),
          milano = list(name = "Milano")
        )
      )
    )
  ),
  america = list(
    name = "America",
    items = list(
      namerica = list(
        name = "North America",
        items = list(
          usa = list(
            name = "USA",
            items = list(
              chicago = list(name = "Chicago"),
              newyork = list(name = "New York")
            )
          ),
          canada = list(
            name = "Canada",
            items = list(
              ottawa = list(name = "Ottawa"),
              toronto = list(name = "Toronto")
            )
          )
        )
      ),
      samerica = list(
        name = "South America",
        items = list(
          brazil = list(
            name = "Brazil",
            items = list(
              brasilia = list(name = "Brasilia"),
              saopolo = list(name = "Sâo Polo")
            )
          ),
          mexico = list(
            name = "Mexico",
            items = list(
              mexicocity = list(name = "Mexico City"),
              tijuana = list(name = "Tijuana")
            )
          )
        )
      )
    )
  )
)

ui <- fluidPage(
  br(),
  NestedMenuOutput("menu", height = "auto"),
  br(),
  verbatimTextOutput("clicked")
)

server <- function(input, output, session){

  output[["menu"]] <- renderNestedMenu({
    NestedMenu(
      "Cities", items = cities
    )
  })

  output[["clicked"]] <- renderPrint({
    input[["menu"]]
  })

}

shinyApp(ui, server)

【讨论】:

  • 谢谢美人。我会尽快测试并恢复!
猜你喜欢
  • 2021-10-20
  • 2023-03-16
  • 2017-10-07
  • 1970-01-01
  • 2015-01-11
  • 2015-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多