繁体   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