是否可以在Shiny中生成带有子选项的pickerInput?

问题描述 投票:0回答:1

我想知道是否可以创建一个像下面的

pickerInput
那样的
Shiny

(请参阅评论,无法发布图片,因为我收到错误“您的帖子主要包含图像”)

r shiny
1个回答
0
投票

您可以使用库(NestedMenu)。

请在此处找到示例:

library(NestedMenu)
library(shiny)

cities <- list(
  europe = list(
    name = "Europe",
    items = list(
      france = list(
        name = "France",
        icon = "fa-cheese",
        items = list(
          paris = list(name = "Paris"),
          lyon = list(name = "Lyon")
        )
      ),
      italy = list(
        name = "Italy",
        icon = "fa-pizza-slice",
        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",
           icon = "fa-flag-usa",
            items = list(
              chicago = list(name = "Chicago"),
              newyork = list(name = "New York")
            )
          ),
          canada = list(
            name = "Canada",
            icon = "fa-canadian-maple-leaf",
            items = list(
              ottawa = list(name = "Ottawa"),
              toronto = list(name = "Toronto")
            )
          )
        )
      ),
      samerica = list(
        name = "South America",
        items = list(
          brazil = list(
            name = "Brazil",
            icon = "fa-lemon",
            items = list(
              brasilia = list(name = "Brasilia"),
              saopolo = list(name = "Sao Polo")
            )
          ),
          mexico = list(
            name = "Mexico",
            icon = "fa-hat-cowboy",
            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)
© www.soinside.com 2019 - 2024. All rights reserved.