Automatic resizing of rChart in brilliant

How can I automatically resize the rChart graph? I would like to fit the plot to the user's screen, as is done for regular plots using renderPlot. Here is a minimal example:

#Server.R require(rCharts) shinyServer(function(input, output) { output$chart1 <- renderChart2({ r1 <- rPlot(mpg ~ wt | am + vs, data = mtcars, type = "point", color = "gear") return(r1) }) }) #ui.R. require(rCharts) options(RCHART_LIB = 'polycharts') shinyUI(shinyUI(fluidPage( titlePanel("title panel"), sidebarLayout( sidebarPanel("sidebar panel"), mainPanel("main panel", chartOutput("chart1", 'polycharts')) ) ) )) 

I tried adding:

 w <- session$clientData$output_chart1_width r1$set(width = w) 

but that will not work.

+5
source share
2 answers

You were almost there: rChart chartOutput does not pass its size, so a workaround is to use the plotOutput object to do this.

Here is a solution that works for me:

 #server.R require(rCharts) shinyServer(function(input, output, session) { output$chart1 <- renderChart2({ r1 <- rPlot(mpg ~ wt | am + vs, data = mtcars, type = "point", color = "gear") r1$set(width = session$clientData$output_plot1_width) return(r1) }) }) #ui.R require(rCharts) options(RCHART_LIB = 'polycharts') shinyUI(shinyUI(fluidPage( titlePanel("title panel"), sidebarLayout( sidebarPanel("sidebar panel"), mainPanel("main panel", plotOutput("plot1", height = "1px"), chartOutput("chart1", 'polycharts') ) ) ) )) 

Note: here is another example that I wrote with a diagram like nvd3: https://gist.github.com/nassimhaddad/3057e9ac687591fa5138

+4
source

I use highcharts and add the HTML right after the showOutput function worked for me.

 #ui.R. require(rCharts) shinyUI(shinyUI(fluidPage( titlePanel("title panel"), sidebarLayout( sidebarPanel("sidebar panel"), mainPanel("main panel", showOutput("chart1", 'highcharts'), HTML('<style>.rChart {width: 100%; height: 600px}</style>')) ) ) )) 

Hope this helps ...

+4
source

Source: https://habr.com/ru/post/1200623/


All Articles