我正在制作的闪亮应用在dashboardSidebar中有多个subMenuItems。我想将这些菜单项中的每一个链接到数据库。 UI代码如下:
dashboardSidebar(
width = 150,
sidebarMenu(
menuItem("By States",
menuSubItem("AP", tabName = "AP"),
menuSubItem("ANP", tabName = "ANP"),
menuSubItem("BIH", tabName = "BIH"),
menuSubItem("TN", tabName = "TN")
)
),
sidebarMenu(
menuItem("Charts",
menuSubItem("AP", tabName = "APC"),
menuSubItem("Anp", tabName = "ANPC")
))
),
我尝试使用服务器中的以下代码将这些子菜单中的每一个附加到数据库中。
datasetInput <- reactive({
if (input$AP == "AP"){
"AP" = readRDS("data/AP.rds")
} else if (input$BIH == "BIH") {
"BIH" = readRDS("data/Bih.rds")
} else if (input$ANP == "ANP") {
"ANP" = readRDS("data/Anp.rds")
} else if (input$TN == "TN") {
"TN" = readRDS("data/tnd.rds")
}
})
我收到以下错误:
Error in if (input$AP == "AP") { : argument is of length zero
ERROR: [on_request_read] connection reset by peer
如何将menuSubItem链接到数据库?我尝试了以下工作正常,但我无法在每个菜单下获得子项目。
正常工作的代码 如下:
dashboardSidebar(
width = 150,
sidebarMenu(id = "tabs",
menuItem("AP", tabName = "AP"),
menuItem("ANP", tabName = "ANP"),
menuItem("BIH", tabName = "BIH"),
menuItem("TN", tabName = "TN")
),
sidebarMenu(id = "charts",
menuItem("AP", tabName = "APC"),
menuItem("Anp", tabName = "ANPC")
)
),
和服务器代码:
datasetInput <- reactive({
switch(input$tabs,
"AP" = readRDS("data/AP.rds"),
"BIH" = readRDS("data/Bih.rds"),
"ANP" = readRDS("data/Anp.rds"),
"TN" = readRDS("data/tnd.rds")
)
})
但这不是渲染subMenus。
答案 0 :(得分:0)
我认为您已经找到了解决方案,但是,要有subMenus:
dashboardSidebar(
width = 150,
sidebarMenu(id = "mysidebar",
menuItem("Tabs",
menuSubItem("ANP", tabName = "ANP"),
menuSubItem(""BIH", tabName = "BIH""),
menuSubItem("TN", tabName = "TN")),
menuItem("Charts",
menuSubItem("AP", tabName = "APC"),
menuSubItem("Anp", tabName = "ANPC"))
),
...
然后使用以下方法访问所选项目:输入$ mysidebar,其中可能的值为:&#34; ANP&#34;,&#34; BIH&#34;等