css 如何调整缩进的项目符号使用HTML(无序列表)在R的光泽环境?

gudnpqoy  于 2023-04-13  发布在  其他
关注(0)|答案(2)|浏览(85)

我正在尝试使用HTML来调整R Shiny模态对话框中呈现的文本的项目符号对齐,如下图所示。我已经浏览了W3 Schools等来源,但还没有找到解决方案。示例代码,在某种程度上代表了我的大型应用程序,在底部发布。对于这种项目符号对齐,是否有任何解决方案?

示例代码:

library(shiny)

ui <- fluidPage(fluidRow(uiOutput("header")))

server <- function(input, output, session) {
  output$header <- renderUI({
    fluidPage(
        paste("Testing modal:"),
        tags$button(
          id = "show", class = "btn action-button",
          tags$img(src = "https://images.plot.ly/language-icons/api-home/python-logo.png")
        )
    )
  })
  
  observeEvent(input$show, {
    showModal(modalDialog(
      tags$div(style="text-align:justify",
      HTML("
      <p>Studying the pig:</p>
      <ul>
      <li>Pigs eat anything</li>
      <li>Pigs are fat</li>
      </ul>
      "))
    ))
  })
}

shinyApp(ui, server)
z4iuyo4d

z4iuyo4d1#

我不确定这是不是最好的方法:

<p>Studying the pig:</p>
      <ul>
      <li style='margin-left: -25px;'>Pigs eat anything</li>
      <li style='margin-left: -25px;'>Pigs are fat</li>
      </ul>
iqih9akk

iqih9akk2#

通常缩进是通过设置ul-tag的padding-left属性来控制的(不需要修改每个li-tag):

library(shiny)

ui <- fluidPage(fluidRow(uiOutput("header")))

server <- function(input, output, session) {
  output$header <- renderUI({
    fluidPage(
      paste("Testing modal:"),
      tags$button(
        id = "show",
        class = "btn action-button",
        tags$img(src = "https://images.plot.ly/language-icons/api-home/python-logo.png")
      )
    )
  })
  observeEvent(input$show, {
    showModal(modalDialog(
      tags$div(style = "text-align: justify;",
               tags$p("Studying the pig:"),
               tags$ul(style = "padding-left: 15px;",
                       lapply(list("Pigs eat anything", "Pigs are fat"), tags$li)
                       )
      )
    ))
  })
}

shinyApp(ui, server)

相关问题