多级下拉悬停 R Shiny

4
我正在寻找一个适用于R Shiny的多级下拉菜单解决方案。 enter image description here 我已经浏览了这里大部分的包,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

这样的小部件应该做什么?当您单击某个项目时,您想要什么? - Stéphane Laurent
请提供要翻译的英文内容。 - Arkadi w
一个复选框树可能不太合适?请参见jsTreeR - Stéphane Laurent
不是真的。我需要一次选择一个。而且它看起来不好看。 - Arkadi w
看起来很不错(可以切换到左键单击吗?) 我稍后可以调整CSS。你有R Shiny版本吗? - Arkadi w
显示剩余3条评论
1个回答

4

我刚完成了一个包,它使用了JavaScript库jquery-contextMenu。要安装它:

remotes::install_github("stla/NestedMenu")

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

enter image description here

使用示例:

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)

非常感谢。我会尽快测试并回复! - Arkadi w

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接