gpt4 book ai didi

css - 在 selectInput 旁边放置按钮

转载 作者:技术小花猫 更新时间:2023-10-29 11:39:45 26 4
gpt4 key购买 nike

目标

我想在我的 shinydashboard::box 的页脚中并排放置一个 selectInput 和一个 actionButton。该按钮应该“相对靠近”selectInput不考虑框的宽度。

到目前为止我尝试了什么

到目前为止,我尝试了 columnsplitLayout 或通过 display: inline-block 进行样式设置,但我对这两种解决方案都不满意:

  • column:根据框的宽度,selectInputactionButton 之间的差距太大(我可以部分解决这个问题将 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)

最佳答案

我希望这可能有用。我将 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)

关于css - 在 selectInput 旁边放置按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51522917/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com