简体   繁体   中英

Adjust UI element positions in shindashboardPlus header

I have a Shiny application with a toggle switch on the Header that. When the toggle is pressed, it runs a long function and a message is displayed to the user that something is happening. A very simplified version is below.

The functionality that I have is fine but the UI isn't aligned. The toggle and the message displayed on the header are slightly higher than the minimizer button (hamburger) to their left. I would like to be able to move the toggle and the message down just a bit so that they are horizontally in line with the minimizer button, but I can't find a way to do this in CSS or the various shiny/shinydashboard/shinydashboardPlus functions.

Also, the output message (and htmlOutput element) is spaced far to the right of the toggle and I would like to close the gap between the toggle and the message.

在此处输入图片说明

library(shiny)
library(shinycssloaders)
library(shinydashboard)
library(shinyjs)
library(shinydashboardPlus)
library(shinyWidgets)

# Define UI for application that draws a histogram
ui <- dashboardPage(skin = 'blue', 
                    
shinydashboardPlus::dashboardHeader(title = 'Example',
    leftUi = tagList(
        useShinyjs(),
        switchInput(inputId = 'swtLabels', label = 'Labels', value = TRUE,
                    onLabel = 'Label 1', offLabel = 'Label 2',
                    onStatus = 'info', offStatus = 'info', size = 'mini', 
                    handleWidth = 230),
        htmlOutput(outputId = 'labelMessage')
        )
    ),
    dashboardSidebar(),
    dashboardBody()
)

server <- function(input, output) {  
  observeEvent(input$swtLabels, {
     shinyjs::html(id = 'labelMessage', html = 'Starting...')
     shinyjs::showElement(id = 'labelMessage')
     Sys.sleep(1)
     shinyjs::html(id = 'labelMessage', html = 'Done') 
     shinyjs::hideElement(id = 'labelMessage', anim = TRUE, animType = 'fade', time = 2.0) 
  })
}

# Run the application 
shinyApp(ui = ui, server = server)

Try margin-top: 6px . See below.

library(shiny)
library(shinycssloaders)
library(shinydashboard)
library(shinyjs)
library(shinydashboardPlus)
library(shinyWidgets)

# Define UI for application that draws a histogram
ui <- dashboardPage(skin = 'blue', 
                    
                    shinydashboardPlus::dashboardHeader(title = 'Example',
                                                        leftUi = tagList(
                                                          useShinyjs(),
                                                          div(switchInput(inputId = 'swtLabels', label = 'Labels', value = TRUE,
                                                                      onLabel = 'Label 1', offLabel = 'Label 2',
                                                                      onStatus = 'info', offStatus = 'info', size = 'mini', 
                                                                      handleWidth = 230), style = "margin: 6px -20px;"),
                                                          div(htmlOutput(outputId = 'labelMessage'), 
                                                              style = "margin: 8px 0px 0px -60px;")
                                                        )
                    ),
                    dashboardSidebar(),
                    dashboardBody()
)

server <- function(input, output) {  
  observeEvent(input$swtLabels, {
    shinyjs::html(id = 'labelMessage', html = 'Starting...')
    shinyjs::showElement(id = 'labelMessage')
    Sys.sleep(1)
    shinyjs::html(id = 'labelMessage', html = 'Done') 
    shinyjs::hideElement(id = 'labelMessage', anim = TRUE, animType = 'fade', time = 2.0) 
  })
}

# Run the application 
shinyApp(ui = ui, server = 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