2017-05-05 55 views
0

從閃亮的儀表板github中,我收集到可以在標題右上角創建下拉菜單,但只有3種「類型」(消息,通知,和任務)。R Shiny Dashboard - Header中的自定義下拉菜單

https://rstudio.github.io/shinydashboard/structure.html#structure-overview

是否有創建自定義下拉列表的方法?我想做一個設置下拉框,我給用戶一些複選框,他們可以用來調整儀表板的方式(顯示/隱藏東西,過濾數據等)

回答

0

Shiny Dashboard是基於admin LTE。因此,現有類型的下拉菜單設計用於管理LTE用例,與許多Shiny應用使用情況完全不同。

如果在管理LTE中甚至沒有可用的功能,那麼Shiny儀表板不太可能支持該功能。你可以把some controls in the side bar。另一種可能性是使用the wrench icon in box,但尚未在Shiny中實現。

1

我自定義了三種菜單類型之一來允許這樣做。你可以添加actionItem(s)的項目。 tabSelect屬性,當真正模擬sidebarMenuItem的選擇。

dropdownActionMenu <- function (..., title=NULL, icon = NULL, .list = NULL, header=NULL) { 
    items <- c(list(...), .list) 
    lapply(items, shinydashboard:::tagAssert, type = "li") 
    type <- "notifications" # TODO créer action + CSS 
    dropdownClass <- paste0("dropdown ", type, "-menu") 
    tags$li(class = dropdownClass, a(href = "#", class = "dropdown-toggle", 
    `data-toggle` = "dropdown", icon, title), tags$ul(class = "dropdown-menu", 
    if(!is.null(header)) tags$li(class="header",header), 
    tags$li(tags$ul(class = "menu", items)))) 
} 

actionItem = function (inputId, text, icon = NULL, tabSelect=FALSE) { 
    if(!is.null(icon)) { 
    shinydashboard:::tagAssert(icon, type = "i") 
    icon <- tagAppendAttributes(icon, class = paste0("text-", "success")) 
    } 
    if(tabSelect) { 
    tags$li(a(onclick=paste0("shinyjs.tabSelect('",inputId,"')"),icon,text)) 
    } else { 
    tags$li(actionLink(inputId,text,icon)) 
    } 
} 

示例代碼

dashboardHeader(
    dropdownActionMenu(title="test", 
    actionItem("mnuFirst","First"), 
    actionItem("mnuSecond","Second") 
) 
) 
+0

謝謝!我最終把它放在邊欄的菜單項中,但我必須嘗試一下。 – FortuneFaded