R Shiny space out下拉列表和单选按钮

时间:2017-06-01 08:03:23

标签: r shiny

我正在尝试将一个下拉列表和一些单选按钮放在一个闪亮的R应用程序的框中的同一行上。请参阅下面的代码。

  box(
    title = "Title"
    ,status = "primary"
    ,div(style="display:inline-block",selectInput('crisis_type_top_10_imp_wors', 'Crisis', c("Composite", "Banking", 
                                                                                              "Currency", "Sovereign", 
                                                                                              "Sudden Stop"), width = "120px"))
    ,div(style="display:inline-block",radioButtons("top_ten_normalisation_type_radio","Normalisation", 
                                                    c("Global" = "Global", 
                                                      "Regional" = "Regional",
                                                      "Own Country" = "Own Country")
                                                    ,inline=T))
    ,solidHeader = FALSE 
    ,collapsible = FALSE 
    ,dataTableOutput("topTen")
    , height = 660
    , width = 6
    , align='ccc'
  )

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以在columns()中构建它:

box(
  title = "Title"
  ,status = "primary"
  ,column(width = 2,
    div(style="display:inline-block",selectInput('crisis_type_top_10_imp_wors', 'Crisis', c("Composite", "Banking", 
                                                                                            "Currency", "Sovereign", 
                                                                                            "Sudden Stop"), width = "120px"))
  )
  ,column(width = 1) #empty column for space in between
  ,column(width = 9,
    div(style="display:inline-block",radioButtons("top_ten_normalisation_type_radio","Normalisation",

  ...
)

完全可重复的例子:

library(shiny)
library(shinydashboard)
body <- dashboardBody(
    box(
      title = "Title"
      ,status = "primary"
      ,column(width = 1,
        div(style="display:inline-block",selectInput('crisis_type_top_10_imp_wors', 'Crisis', c("Composite", "Banking", 
                                                                                                "Currency", "Sovereign", 
                                                                                                "Sudden Stop"), width = "120px"))
      )
      ,column(width = 1)
      ,column(width = 10,
        div(style="display:inline-block",radioButtons("top_ten_normalisation_type_radio","Normalisation", 
                                                       c("Global" = "Global", 
                                                         "Regional" = "Regional",
                                                         "Own Country" = "Own Country")
                                                       ,inline=T))
      )

      ,solidHeader = FALSE 
      ,collapsible = FALSE 
      ,dataTableOutput("topTen")
      , height = 660
      , align='ccc'
      , width = 12
    )
)

shinyApp(
  ui = dashboardPage(
    dashboardHeader(title = "tabBoxes"),
    dashboardSidebar(),
    body
  ),
  server = function(input, output) {
    # The currently selected tab from the first box
    output$tabset1Selected <- renderText({
      input$tabset1
    })
  }
)