2017-05-25 2 views
0

Lorsque vous basculez le menu de la barre d'outils du tableau de bord, les graphiques et les tableaux (créés via R Shiny) ne modifient pas leur largeur en conséquence.R Brillant, tableau de bord La barre latérale casse les graphiques et la largeur des tables lors du basculement

Voici un exemple avec un graphique et une table standard. Lors de l'initialisation de l'application, le graphique et la table remplissent l'écran correctement, mais en basculant le menu, la largeur des deux éléments est rompue.

Comment cela peut-il être fixé de sorte que leur largeur soit de 100% à tout moment?

library(shiny) 
library(shinydashboard) 
library(dygraphs) 

ui <- dashboardPage(
    dashboardHeader(), 

    dashboardSidebar(
     sidebarMenu(id = "menu_tabs", 
      menuItem("Test", tabName = "page_1", icon = icon("table"), selected = TRUE)     
     ) 
    ), 

    dashboardBody( 
     tabItems(  
      tabItem(tabName = "page_1",    
       fluidRow(
        column(width = 12, offset = 0, 
         box(width = 12, 
          dygraphOutput("dy_plot", height = "310px") 
         ) 
        ) 
       ), 

       fluidRow(
        column(width = 12, offset = 0, 
         box(width = 12, 
          dataTableOutput('mytable') 
         ) 
        ) 
       )    
      )   
     ) 
    ) 
) 

server <- function(input, output) { 

    output$mytable = renderDataTable({ 
     mtcars 
    }, 
    options = list(
     lengthMenu = c(30), 
     pageLength = 30, 
     searching = FALSE, 
     paging = FALSE, 
     ordering = FALSE, 
     scrollX = TRUE)) 

    output$dy_plot <- renderDygraph({ 
     lungDeaths <- cbind(mdeaths, fdeaths) 
     dygraph(lungDeaths) 
    }) 
} 

shinyApp(ui, server) 

Répondre

0

beaucoup de crédit va à cette réponse Shiny dashboard does not scale well où vous pouvez forcer le redimensionnement

rm(list = ls()) 
library(shiny) 
library(shinydashboard) 
library(dygraphs) 

ui <- dashboardPage(
    dashboardHeader(), 

    dashboardSidebar(
    sidebarMenu(id = "menu_tabs",menuItem("Test", tabName = "page_1", icon = icon("table"), selected = TRUE)     
    ) 
), 

    dashboardBody( 
    tags$script(' 
     // Bind function to the toggle sidebar button 
     $(".sidebar-toggle").on("click",function(){ 
     $(window).trigger("resize"); // Trigger resize event 
     })' 
    ), 
    tabItems(  
     tabItem(tabName = "page_1",    
       fluidRow(
       column(width = 12, offset = 0, 
         box(width = 12, 
          dygraphOutput("dy_plot", width = "100%", height = "310px") 
         ) 
       ) 
      ), 

       fluidRow(
       column(width = 12, offset = 0, 
         box(width = 12, 
          dataTableOutput('mytable') 
         ) 
       ) 
      )    
    )   
    ) 
) 
) 

server <- function(input, output) { 

    output$mytable = renderDataTable({ 
    mtcars 
    }, 
    options = list(
    lengthMenu = c(30), 
    pageLength = 30, 
    searching = FALSE, 
    paging = FALSE, 
    ordering = FALSE, 
    scrollX = TRUE)) 

    output$dy_plot <- renderDygraph({ 
    lungDeaths <- cbind(mdeaths, fdeaths) 
    dygraph(lungDeaths) 
    }) 
} 

shinyApp(ui, server) 

enter image description here

0

En fait, cela a été corrigé dans la dernière version de shinydashboard. Il suffit de le réinstaller depuis le CRAN:

install.packages("shinydashboard")