2017-10-13 115 views
-1

如何使菜單項徽章與默認對齊方式不同? 在shinyUI:shinydashboard徽章menuitem

menuItem("Test", tabName = "test", icon = icon("line-chart"),badgeLabel = "2nd", badgeColor = "green") 

完整例如:

library(shiny) 
library(shinydashboard) 
# Default shiny 
ui <- dashboardPage(
dashboardHeader(title = "Example"), 
dashboardSidebar(
sidebarMenu(
    menuItem("Test", tabName = "test", icon = icon("line-chart"), 
    badgeLabel = "2nd", badgeColor = "green") 
)), 
dashboardBody(
tabItems(
    tabItem(tabName = "test", 
     box(title = "How-to",status = "primary",solidHeader = TRUE,collapsible=TRUE, width = 8, 
     sliderInput("bins", 
       "Number of bins:", 
       min = 1, 
       max = 50, 
       value = 30), 
    # Show a plot of the generated distribution 
    plotOutput("distPlot") 
    ) 
    ) 
))) 
# Define server logic required to draw a histogram 
server <- function(input, output) { 
    output$distPlot <- renderPlot({ 
    # generate bins based on input$bins from ui.R 
    x <- faithful[, 2] 
    bins <- seq(min(x), max(x), length.out = input$bins + 1) 

    # draw the histogram with the specified number of bins 
    hist(x, breaks = bins, col = 'darkgray', border = 'white') 
    }) 
} 
# Run the application 
shinyApp(ui = ui, server = server) 

在瀏覽器檢查它示出了下面的代碼/:

<small class="badge pull-right bg-green">2nd</small> 

測試PIC

enter image description here

我需要:

<small class="badge center-block bg-green">2nd</small> 

所需PIC

enter image description here

任何想法?

+0

歡迎來到SO。請參閱[我如何提出一個好問題?](https://stackoverflow.com/help/how-to-ask),特別是包含足夠的代碼以允許其他人重現問題。有關此方面的幫助,請閱讀[如何創建最小,完整和可驗證示例](https://stackoverflow.com/help/mcve)。它將幫助每個人重現相同的問題並幫助你。 – rmjoia

回答

0

您可以使用CSS如下: tags$style(type = 'text/css',".badge{min-width: 200px;}")

在你的代碼,它會來是這樣的:

library(shiny) 
    library(shinydashboard) 
    # Default shiny 
    ui <- dashboardPage(
     dashboardHeader(title = "Example"), 
     dashboardSidebar(
     ##The added css 
     tags$style(type = 'text/css',".badge{min-width: 200px;}"), 
     sidebarMenu(
      menuItem("Test", tabName = "test", icon = icon("line-chart"), 
        badgeLabel = "2nd", badgeColor = "green") 
     )), 
     dashboardBody(
     tabItems(
      tabItem(tabName = "test", 
        box(title = "How-to",status = "primary",solidHeader = TRUE,collapsible=TRUE, width = 8, 
         sliderInput("bins", 
            "Number of bins:", 
            min = 1, 
            max = 50, 
            value = 30), 
         # Show a plot of the generated distribution 
         plotOutput("distPlot") 
       ) 
     ) 
     ))) 
    # Define server logic required to draw a histogram 
    server <- function(input, output) { 
     output$distPlot <- renderPlot({ 
     # generate bins based on input$bins from ui.R 
     x <- faithful[, 2] 
     bins <- seq(min(x), max(x), length.out = input$bins + 1) 

     # draw the histogram with the specified number of bins 
     hist(x, breaks = bins, col = 'darkgray', border = 'white') 
     }) 
    } 
    # Run the application 
    shinyApp(ui = ui, server = server) 

你得到這樣的事情:enter image description here

希望它能幫助!

+0

謝謝!它可以工作,因此標籤$ style可以更改袋子。 – varbirog

+0

實際上,'tag $ style'可以用來使用原始CSS來設計不同的元素。 – SBista