简体   繁体   English

在 Shiny 应用程序中对齐 ActionButton

[英]Align ActionButton in Shiny App

In the app below, I would like to change three aspects of the ActionButton :在下面的应用程序中,我想更改ActionButton的三个方面:

  1. Center the button in its column使按钮在其列中居中
  2. Reduce the spacing between the button and the top text缩小按钮和顶部文本之间的间距
  3. Increase the spacing between the button and the panels below.增加按钮和下面面板之间的间距。

Can this be done within shiny?这可以在 shiny 内完成吗?

library(shiny)
library(shinyBS)

ui <- 
  fluidPage(
    fluidRow(
      column(12,
             bsCollapse(id="instructionsOutput", open="instructionsPanel",
                        bsCollapsePanel("instructionsPanel",
                                        "This is a panel with text",
                                        style="info"
                                        )
                        )
             ),
      column(12,
             actionButton("p1Button", "Expand/Collapse Text")
             )
    ),
  sidebarLayout(
    sidebarPanel(),
    mainPanel()
  )
)

server <- function(input, output, session) {
  observeEvent(input$p1Button, ({
                updateCollapse(session, "instructionsOutput",
                               open="instructionsPanel",
                               close="instructionsPanel")  
  })
  )

}

shinyApp(ui, server)

Very late reply...but if anyone is looking for a possible solution, you can try the following.回复很晚...但如果有人正在寻找可能的解决方案,您可以尝试以下操作。 Similar to the answer by Xiongbing Jin above, you can add style and align as arguments to shiny::column与上面 Xiongbing Jin 的回答类似,您可以将stylealign作为参数添加到shiny::column

ui <- 
  fluidPage(
    fluidRow(
      column(
        12,
        bsCollapse(
          id="instructionsOutput", 
          open="instructionsPanel",
          bsCollapsePanel(
            "instructionsPanel",
            "This is a panel with text",
            style="info"
          )
        )
      ),
      column(
        12,
        actionButton(
          "p1Button", 
          "Expand/Collapse Text"
        )
        , align = "center"
        , style = "margin-bottom: 10px;"
        , style = "margin-top: -10px;"
      )
    ),
    sidebarLayout(
      sidebarPanel(),
      mainPanel()
    )
  )

server <- function(input, output, session) {
  observeEvent(input$p1Button, ({
    updateCollapse(
      session, "instructionsOutput",
      open="instructionsPanel",
      close="instructionsPanel"
    )  
  })
  )

}

shinyApp(ui, server)

Thanks @rhyncogale.谢谢@rhyncogale。 I applied your comment and it worked for my work.我应用了你的评论,它对我的工作有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM