tho*_*hal 5 css twitter-bootstrap shiny shinydashboard
目标
我要放置selectInput和actionButton并排在我的页脚侧shinydashboard::box.selectInput 无论盒子的宽度如何,按钮都应该"相对靠近" .
到目前为止我尝试过的
到目前为止,我尝试过column,splitLayout或通过样式display: inline-block,但我不满意任何一种解决方案:
column:取决于盒子的宽度,selectInput和之间的间隙actionButton太大(我可以通过将selectInput宽度扩展到100%来部分解决,但宽度太大)splitDesign:到目前为止最好的选择,但cellWidths需要基于盒子的调整width,也只有100%的selectInput宽度工作,对于大盒子,第二次分割的宽度似乎太大了inline-block:与一般不搭配 CSS例
library(shiny)
library(purrr)
library(shinydashboard)
widths <- c(1, 2,3, 4, 6, 12)
makeBoxes <- function(width, method = c("split", "col", "css")) {
method <- match.arg(method)
split <- function(width, count) {
splitLayout(selectInput(paste("sel", width, count, sep = "_"), NULL, LETTERS,
width = "100%"),
actionButton(paste("ab", width, count, sep = "_"), icon("trash")),
cellWidths = c("87.5%", "12.5%"),
cellArgs = list(style = "vertical-align: top"))
}
col <- function(width, count) {
fluidRow(column(width = 11,
selectInput(paste("sel", width, count, sep = "_"), NULL, LETTERS,
width = "100%")),
column(width = 1,
actionButton(paste("ab", width, count, sep = "_"), icon("trash"))))
}
css <- function(width, count) {
fluidRow(div(selectInput(paste("sel", width, count, sep = "_"), NULL, LETTERS),
style = "display: inline-block; vertical-align: top"),
actionButton(paste("ab", width, count, sep = "_"), icon("trash")))
}
wrap <- function(method, ...)
switch(method, split = split(...), col = col(...), css = css(...))
map(seq(1, 12 / width, 1), function(count)
box(solidHeader = TRUE, title = "Box", status = "info", width = width,
footer = wrap(method, width, count)))
}
server <- function(input, output) {
}
ui1 <- dashboardPage(dashboardHeader(), dashboardSidebar(),
dashboardBody(map(widths, ~ fluidRow(makeBoxes(.x, "split")))))
ui2 <- dashboardPage(dashboardHeader(), dashboardSidebar(),
dashboardBody(map(widths, ~ fluidRow(makeBoxes(.x, "col")))))
ui3 <- dashboardPage(dashboardHeader(), dashboardSidebar(),
dashboardBody(map(widths, ~ fluidRow(makeBoxes(.x, "css")))))
shinyApp(ui1, server)
shinyApp(ui2, server)
shinyApp(ui3, server)
Run Code Online (Sandbox Code Playgroud)
我希望这会有用。我将 width = 11 更改为 12,这对我来说似乎很好。
那是你要的吗 ?
library(shiny)
library(purrr)
library(shinydashboard)
widths <- c(1, 2,3, 4, 6, 12)
makeBoxes <- function(width, method = c("split", "col", "css")) {
method <- match.arg(method)
split <- function(width, count) {
splitLayout(selectInput(paste("sel", width, count, sep = "_"), NULL, LETTERS,
width = "100%"),
actionButton(paste("ab", width, count, sep = "_"), icon("trash")),
cellWidths = c("87.5%", "12.5%"),
cellArgs = list(style = "vertical-align: top"))
}
col <- function(width, count) {
fluidRow(column(width = 12, # width = 11 -> 12
selectInput(paste("sel", width, count, sep = "_"), NULL, LETTERS,
width = "100%")),
column(width = 1,
actionButton(paste("ab", width, count, sep = "_"), icon("trash"))))
}
css <- function(width, count) {
fluidRow(div(selectInput(paste("sel", width, count, sep = "_"), NULL, LETTERS),
style = "display: inline-block; vertical-align: top"),
actionButton(paste("ab", width, count, sep = "_"), icon("trash")))
}
wrap <- function(method, ...)
switch(method, split = split(...), col = col(...), css = css(...))
map(seq(1, 12 / width, 1), function(count)
box(solidHeader = TRUE, title = "Box", status = "info", width = width,
footer = wrap(method, width, count)))
}
server <- function(input, output) {
}
ui2 <- dashboardPage(dashboardHeader(), dashboardSidebar(),
dashboardBody(map(widths, ~ fluidRow(makeBoxes(.x, "col")))))
shinyApp(ui2, server)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
314 次 |
| 最近记录: |