简体   繁体   中英

Aligning checkboxInput along with the box title in shiny

I have a shiny application, where in I am trying to provide a checkbox on top of a graph for the user to select. Currently, the check box is rendered below the title, whereas I want the title on the left hand side and the check box on the right hand side in the same line. I am sure it can be achieved through recoding CSS, but don't know how. The current code looks as follows:

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
    dashboardHeader(
        title = "MODULE",titleWidth = 225
    ),
    dashboardSidebar(
        width = 225,
        sidebarMenu(id = "tabs",
                    menuItem("TOPLINES", tabName = "tplines", icon = shiny::icon("dashboard"))
        )),
    dashboardBody(
        tabItems(
            tabItem(
                tabName = "tplines",
                fluidRow(
                    box(
                        checkboxInput(inputId = "inventorytop8metrocheck", "Add to reports", value = FALSE),
                        width = 6, status = "info", title = "Inventory information",
                        div(plotlyOutput("inventorytop8metro"), width = "100%", height = "400px", style = "font-size:80%;")
                    )
                    )))))

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

}

shinyApp(ui,server)

Maybe you are just looking for the standard row partition with columns . The title arguement takes any ui elements, so we input a row that is half your original title and half the checkbox input. Thus, they are in line. Of course, the checkbox then has the same style as the title. If you don't want that, you can alter the style by setting a style parameter in the checkbox column.

library(shiny)
library(shinydashboard)
library(plotly)

ui <- dashboardPage(
  dashboardHeader(
    title = "MODULE",titleWidth = 225
  ),
  dashboardSidebar(
    width = 225,
    sidebarMenu(id = "tabs",
      menuItem("TOPLINES", tabName = "tplines", icon = shiny::icon("dashboard"))
  )),
  dashboardBody(
    tabItems(
      tabItem(
        tabName = "tplines",
        fluidRow(
          box(
            width = 6, status = "info", title = fluidRow(
              column(6, "Inventory information"),
              column(6, checkboxInput(inputId = "inventorytop8metrocheck", "Add to reports", value = FALSE))
            ),
            div(plotlyOutput("inventorytop8metro"), width = "100%", height = "400px", style = "font-size:80%;")
          )
        )
      )
    )
  )
)

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

shinyApp(ui,server)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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