簡體   English   中英

調整 shindashboardPlus 標題中的 UI 元素位置

[英]Adjust UI element positions in shindashboardPlus header

我有一個 Shiny 應用程序,標題上有一個切換開關。 當按下切換鍵時,它會運行一個長函數,並向用戶顯示一條消息,表明正在發生某些事情。 下面是一個非常簡化的版本。

我擁有的功能很好,但 UI 沒有對齊。 標題上顯示的切換和消息略高於其左側的最小化按鈕(漢堡包)。 我希望能夠將切換按鈕和消息向下移動一點,以便它們與最小化按鈕水平對齊,但我找不到在 CSS 或各種閃亮/閃亮儀表板/閃亮儀表板Plus 中執行此操作的方法職能。

此外,輸出消息(和 htmlOutput 元素)位於切換開關右側很遠的位置,我想縮小切換開關和消息之間的間隙。

在此處輸入圖片說明

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)

嘗試margin-top: 6px 見下文。

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)

輸出

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM