我使用的dropdownButton功能從這個鏈接drop-down checkbox input in shiny即在shinyWidgets,有輕微的修改,使得文字爲黑色。dropdownButton對準內dashboardSidebar
我想dropdownButton看起來像selectInput下拉我把它上面儘可能多地。我讓他們在列(1,)函數的邊欄中排隊,但我也希望dropdownButton的寬度與selectInput的寬度相同。
我也得到了下拉選擇的寬度是其上方的selectInput與寬度= 200的寬度相同,但我想下拉按鈕也具有相同的尺寸。
人可以幫我修改dropDownButton功能或我的界面,因此這種情況?
library(shiny)
library(shinydashboard)
dropdownButton2 <- function(label = "", status = c("default", "primary", "success", "info", "warning", "danger"), ..., width = NULL) {
status <- match.arg(status)
# dropdown button content
html_ul <- list(
class = "dropdown-menu",
style = if (!is.null(width))
paste0("width: ", validateCssUnit(width), ";"),
lapply(X = list(...), FUN = tags$li, style = "margin-left: 10px; margin-right: 10px;color:black")
)
# dropdown button apparence
html_button <- list(
class = paste0("btn btn-", status," dropdown-toggle"),
type = "button",
` data-toggle` = "dropdown"
)
html_button <- c(html_button, list(label))
html_button <- c(html_button, list(tags$span(class = "caret")))
# final result
tags$div(
class = "dropdown",
do.call(tags$button, html_button),
do.call(tags$ul, html_ul),
tags$script(
"$('.dropdown-menu').click(function(e) {
e.stopPropagation();
});")
)
}
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(width = 325,
selectInput('month',label='Filter 1:',choices= month.name,multiple = FALSE,selected = "March"),
br(),
column(1,
h5(strong(("Filter 2:"))),
dropdownButton2(
label = "Filter 2:", status = "default", width = 200,#circle = FALSE,
checkboxGroupInput(inputId = "check1", label = "Choose", choices = c("A","B","C"))
)
)),
dashboardBody()
)
server <- function(input, output){
}
shinyApp(ui = ui, server = server)
完美!這正是我想要的。 – SarahGC
所以一個問題,現在我來了防空火炮的是,我寧願下拉按鈕的大小是被動的,因爲selectInput按鈕是一個基於窗口的大小兩種不同尺寸之間去。我嘗試過標記$ style(type ='text/css',「.btn-default {width:100%;}」),但是在某些窗口大小的按鈕變小,下一個側邊欄項重疊它...你會知道如何解決這個問題? – SarahGC