R闪亮:absolutePanel中的并排UI输入

时间:2019-03-08 02:32:23

标签: r shiny

我试图让两个selectInputs在Shiny App的绝对面板中并排显示。我尝试使用解决方案here,特别是使用:

withTags(div(class='row-fluid',
         div(class='span3', checkboxInput(inputId = 
             "simOption", label = "Historical Data",value=TRUE)),
         div(class='span5', checkboxInput(inputId = 
             "simOption2", label = "Historical Data 2",value=TRUE))
          ))

但这在我的代码中不起作用(checkboxInputs仍然垂直显示)。

有关特定示例,请参见以下代码。现在,两个selectInputs垂直出现,而我希望它们可以并排放置。

library(shiny)

ui <- fluidPage(
 navbarPage("Title", id="nav",
  tabPanel("Tab",
   div(class="outer",
    absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
    draggable = TRUE, top = 60, left = "auto", right = 20, bottom = "auto",
    width = 300, height = "auto",

    selectInput("select_1", "1st Thing", 
                choices=1:10, selected = 1, multiple = FALSE,
                width=90),

    selectInput("select_2", "2nd Thing", 
                choices=1:10, selected = 2, multiple = FALSE,
                width=90)  

      )
     )
    )
   )                   
  )

server <- function(input, output, session) {
}

shinyApp(ui, server)

1 个答案:

答案 0 :(得分:1)

您可以将两个输入选择器包装在div中并添加一些CSS。

library(shiny)

ui <- fluidPage(
navbarPage("Title", id="nav",
         tabPanel("Tab",
                  div(class="outer",
                      absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
                                    draggable = TRUE, top = 60, left = "auto", right = 20, bottom = "auto",
                                    width = 300, height = "auto",

                                    div(style="display:flex",
                                        selectInput("select_1", "1st Thing", 
                                                choices=1:10, selected = 1, multiple = FALSE,
                                                width=90),
                                        selectInput("select_2", "2nd Thing", 
                                                choices=1:10, selected = 2, multiple = FALSE,
                                                width=90)
                                        )
                                    )
                      )
                  )
         )
)
server <- function(input, output, session) {
}
shinyApp(ui, server)