我正在尝试制作几个滑块,标签位于滑块左侧滑块上而不是滑块上。
我看到了这两个解决方案:
https://github.com/rstudio/shiny/issues/1737
Label next to selectInput in shiny
然而,它们似乎不适用于新的闪亮模板。标签和滑块确实变成了内联,但滑块的大小确实缩小了。
如果我手动将.irs-line width设置为特定的像素数,我会得到一个合适的大小滑块,但在不同的屏幕上或者窗口最小化时看起来很糟糕。如果我尝试制作它" auto"或" 100%",我回到了" dot"而不是滑块。
可重复的例子:
library(shiny)
ui <- fluidPage(
sidebarPanel(
width = 4,
div(HTML("<b>Bla bla bla bla bla</b>")),
br(),
tags$head(
tags$style(type="text/css",
"label.control-label, .selectize-control.single {
display: table-cell;
text-align: center;
vertical-align: middle;
}
label.control-label {
padding-right: 10px;
}
.form-group {
display: table-row;
}
.selectize-control.single div.item {
padding-right: 15px;
}
.irs-line{
width: 100%;
}")
),
sliderInput("lbl1", "label 1", min = 0, max = 10, value = 0, step = 1),
sliderInput("lbl2", "label 2", min = 0, max = 10, value = 0, step = 1),
sliderInput("lbl3", "label 3", min = 0, max = 10, value = 0, step = 1),
sliderInput("lbl4", "long label number 4", min = 0, max = 10, value = 0, step = 1),
sliderInput("lbl5", "label 5", min = 0, max = 10, value = 0, step = 1),
sliderInput("lbl6", "label 6", min = 0, max = 10, value = 0, step = 1),
sliderInput("lbl7", "label 7", min = 0, max = 10, value = 0, step = 1),
sliderInput("lbl8", "label 8", min = 0, max = 10, value = 0, step = 1),
sliderInput("lbl9", "label 9", min = 0, max = 10, value = 0, step = 1)
)
)
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
答案 0 :(得分:0)
我不是专家,但我会分享我所知道的:
您始终可以使用相对大小在div上配置窗口小部件。
例如,使用width:10vw
(vw表示屏幕宽度)和height:10vh
(vh表示屏幕高度)。
我应用了此代码并修改了您的代码,似乎对我有用。
library(shiny)
ui <- fluidPage(
sidebarPanel(
div(style="width:10vw;",
width = 4,
div(HTML("<b>Bla bla bla bla bla</b>")),
br(),
tags$head(
tags$style(type="text/css",
"label.control-label, .selectize-control.single {
text-align: center;
vertical-align: middle;
}
label.control-label {
padding-right: 20vw;
}
.form-group {
display: table-row;
}
.selectize-control.single div.item {
padding-right: 20vw;
}
")
),
sliderInput("lbl1", "label 1", min = 0, max = 10, value = 0, step = 1),
sliderInput("lbl2", "label 2", min = 0, max = 10, value = 0, step = 1),
sliderInput("lbl3", "label 3", min = 0, max = 10, value = 0, step = 1),
sliderInput("lbl4", "long label number 4", min = 0, max = 10, value = 0, step = 1),
sliderInput("lbl5", "label 5", min = 0, max = 10, value = 0, step = 1),
sliderInput("lbl6", "label 6", min = 0, max = 10, value = 0, step = 1),
sliderInput("lbl7", "label 7", min = 0, max = 10, value = 0, step = 1),
sliderInput("lbl8", "label 8", min = 0, max = 10, value = 0, step = 1),
sliderInput("lbl9", "label 9", min = 0, max = 10, value = 0, step = 1)
)
))
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)