如何在不破坏标签文本的情况下缩短数字输入框的输入字段?
问题描述:
如何缩短放置在侧面板上的数字输入框的输入字段,使其上面的长文字label
不被破坏?请参阅下面的例子:如何在不破坏标签文本的情况下缩短数字输入框的输入字段?
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(numericInput("num_input", "This is long text that should not be broken", value = 0)),
mainPanel()))
server <- function(input, output, session) {}
shinyApp(ui, server)
我知道numericInput
有width
的说法,但缩短了盒子,将导致label
文本换行,我不想。
答
您可以使用CSS来设置标签元素的white-space
属性。在这种情况下,我在div
标签内完成了造型:
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
# white-space: nowrap; ensures that the label doesn't wrap
# as the app window becomes smaller
div(style = "white-space: nowrap;",
numericInput("num_input", "This is long text that should not be broken",
width = 280, value = 0)
)
),
mainPanel()))
server <- function(input, output, session) {}
shinyApp(ui, server)