2017-10-13 6 views
-1

Comment faire un menutem badge pour aligner différemment que par défaut? dans le shinyUI .:badge shinydashboard menuitem

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

Exemple complet:

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) 

Dans le navigateur inspectant montre le code suivant /:

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

pic test

enter image description here

J'ai besoin:

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

pic souhaité

enter image description here

Toute idée?

+0

Bienvenue chez SO. S'il vous plaît se référer à [Comment puis-je poser une bonne question?] (Https://stackoverflow.com/help/how-to-ask), spécialement le code Inclure juste assez pour permettre aux autres de reproduire le problème. Pour obtenir de l'aide, lisez [Comment créer un exemple minimal, complet et vérifiable] (https://stackoverflow.com/help/mcve). Cela aidera tout le monde à reproduire le même problème et à vous aider. – rmjoia

Répondre

0

Vous pouvez utiliser css comme suit: tags$style(type = 'text/css',".badge{min-width: 200px;}")

Dans votre code, il serait venu quelque chose comme ceci:

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) 

vous obtenez quelque chose comme ceci: enter image description here

Hope it helps!

+0

Merci! Cela fonctionne donc les tags $ style peuvent changer le bage. – varbirog

+0

En fait, 'tag $ style' peut être utilisé pour styliser les différents éléments en utilisant CSS brut. – SBista