【问题标题】:How do you left and right align parts of a text in RShiny's UI?如何在 RShiny 的 UI 中左右对齐部分文本?
【发布时间】:2021-05-08 02:05:57
【问题描述】:

运行这个小程序后看到红色文字。我想右对齐该部分。

我认为这很简单。除了正确的答案,我什么都试过了。

library(shiny)
library(shinythemes)

ui=fluidPage(
  navbarPage("hi",theme=shinytheme("cerulean"), 
    tabPanel("example", fluid = TRUE, icon = icon("globe-americas"),
      sidebarLayout(
        sidebarPanel( p(style="text-align: center; ","sidepanel text")
        ),
        mainPanel(
          fluidRow(column(width=12,
            p("first box",style="font-size:125%;padding:12px;color:black; background-color:#fafafc"),
            div(strong("All I want is"),
                br(),
                p("for the text in red",span("to be on the right side of this container",style="align-text: right; color: red"),
                  br(),
                style="font-size:125%;padding:12px;color:black; background-color:#fafafc"),
            hr(),
            ),                   
           column(width=12,p("third box",style="font-size:125%;padding:12px;color:black; background-color:#fafafc"))
        ))
    )))))

  server=function(input, output,session) {}
  shinyApp(ui=ui, server=server)

【问题讨论】:

标签: r shiny text-align right-align


【解决方案1】:

在尝试模仿 HTML DOM 结构和元素类的同时使用 HTML 标记进行此操作,就像 Shiny 创建它们的方式一样。

一个 12 宽的列中的两个 6 宽的列元素将内容并排放置。我在每一列内没有太大变化。

library(shiny)
library(shinythemes)

ui <- fluidPage(
  navbarPage(
    "hi", theme=shinytheme("cerulean"), 
    tabPanel("example", fluid = TRUE, icon = icon("globe-americas"),
             sidebarLayout(
               
               sidebarPanel(p(style="text-align: center; ","sidepanel text")),
               
               mainPanel(
                 fluidRow(
                   div("first box",
                       style="font-size:125%;padding:12px;color:black; background-color:#fafafc", 
                       class="col-sm-12"
                   ),
                   column(12L, strong("All I want is")), 
                   div(
                     div(p("for the text in red", 
                           style="text-align:left; color:black"),
                         class = "col-sm-6", style = "padding-left:0"),
                     div(p("to be on the right side of this container", 
                           style="text-align:right; color:red"),
                         class = "col-sm-6", style = "padding-right:0"),
                     style="font-size:125%;padding:12px;background-color:#fafafc; margin-top:12px", 
                     class="col-sm-12")
                 ),
                 hr(),
                 fluidRow(
                   div("third box",
                       style="font-size:125%;padding:12px;color:black; background-color:#fafafc", 
                       class="col-sm-12")
                 )
               )
             )
)))

server=function(input, output,session) {}

shinyApp(ui=ui, server=server)

【讨论】:

  • 欣赏它。虽然我想补充一点,在 stackoverflow 上说“谢谢”的预期方式是接受和/或赞成。
猜你喜欢
  • 2012-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-20
  • 2014-12-12
  • 2021-08-26
  • 2015-04-24
  • 1970-01-01
相关资源
最近更新 更多