简体   繁体   中英

Highcharter is NOT automatically resize output in shinydashboard

The development-version of highcharter package has the following issue:

highchartOutput DOES NOT automatically resize the width of the plot when hiding the sidebar in shinydashboard. The width of the plot always remains same.

I provide an example here,

# install development-version of highcharter
# devtools::install_github("jbkunst/highcharter")

library(shinydashboard)
library(shiny)
library(highcharter)
library(dplyr)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    box(
      width = 12,
      highchartOutput("plot")
    )
  )
)

server <- function(input, output) {

  output$plot <- renderHighchart({
    highcharts_demo()
  })
}

shinyApp(ui, server)

显示侧边栏

侧边栏被隐藏

I have tried

$(document).on("click", ".sidebar-toggle", function() { $(window).trigger("resize"); });

BUT it still does not work for development-version highcharter when I use renderHighchart & highchartOutput functions.

However, I found

  • renderHighchart2 and highchartOutput2 working well for resizing.

  • BUT renderHighchart2 and highchartOutput2 DO NOT support heatmap, I still need to use renderHighchart and highchartOutput to get correlation plot.

ANY suggestions for this resizing problem?

After doing more research, I got the solution. In the development-version highcharter , fix the code in highcharter.js file as following:

/* fix bug here */
 resize: function(el, width, height, instance) {

   /* http://stackoverflow.com/questions/18445784/ */
   var chart = $("#" +el.id).highcharts();
   var height = chart.renderTo.clientHeight; 
   var width = chart.renderTo.clientWidth; 
   chart.setSize(width, height); 

 }

Then the automatic resizing will work appropriately.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM