[英]Shiny: Align text in textInput
我有一个带有输入字段(textInput)的闪亮应用程序。 我想将输入文本右对齐。 在CSS中,它将类似于text-align: right;
。 有人有想法我可以做到吗?
您可以在下面找到一个代码示例。
ui <- fluidPage(
textInput("text", "Enter your text here")
)
server <- function(input, output) {
output$value <- renderText({ input$text })
}
shinyApp(ui, server)
我认为应该有一种向textInput
添加样式参数的方法,以便可以将style="text-align: right"
传递给textInput
。 无论如何,这是一种方法-
ui <- fluidPage(
HTML(
'<div class="form-group shiny-input-container">
<label for="text">Enter text here</label>
<input id="text" type="text" style="text-align: right" class="form-control" value=""/>
</div>'
),
textOutput("value")
)
server <- function(input, output) {
output$value <- renderText({
input$text
})
}
shinyApp(ui, server)
我这样做的方法只是在控制台中获取textInput("text", "Enter your text here")
,然后将style
属性手动添加到<input>
。 为了重复使用,您可以将其变成一个函数,并将其right_textInput()
或其他名称。
另一种方法是将css
添加到您的inputId
,在本例中为#text
。 但是,您必须对要右对齐的每个textInput
进行此操作-
ui <- fluidPage(
tags$head(tags$style(HTML("#text text-align: right")))
textInput("text", "Enter text here"),
textOutput("value")
)
server <- function(input, output) {
output$value <- renderText({
input$text
})
}
shinyApp(ui, server)
要在fluidRow
右侧获取textInput
,请使用以下示例。
library(shiny)
ui <- fluidPage(
fluidRow(textInput("text", "Enter your text here"), align = 'right')
)
server <- function(input, output) {
sampleText <- renderText({input$text })
}
shinyApp(ui, server)
您可以应用CSS,请参见https://shiny.rstudio.com/articles/css.html 。在HTML中,文本输入的ID应为“ text”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.