3

I try to include in my shiny app two graphs (rCharts,highcharts) with different sizes, but when I change the input to the first graph it immediately takes the size of the second.

I tried to find the answer in the last few days, but without success. A similar question, but no answer: this One more: this

Information in the discussion here is not working for me. Although maybe I made mistakes somewhere.

Here is a minimal example:

ui:

shinyUI(navbarPage("Test",

      tabPanel("First", 
        sidebarLayout(
          sidebarPanel(
            selectInput("Select", 
              label = "Select", 
              choices = c("First", "Second"))),

            mainPanel(
            showOutput("chart1", "highcharts")

              ))),

      tabPanel("Second", 
        sidebarLayout(
          sidebarPanel(
            selectInput("Select2", 
              label = "Select2", 
              choices = c("First", "Second"))),


            mainPanel(
            showOutput("chart2", "highcharts")

            )))))

server:

    require(rCharts)
shinyServer(function(input, output) {  
  output$chart1 <- renderChart2({
    value <- as.character(input$Select)
    x <- data.frame(x = seq(1:6), 
                    y = c(rep("First",times = 3),rep("Second",times = 3)))
    x <- x[x$y == value,]

    a <- rCharts::Highcharts$new()

    a$chart(type = "column")
    a$params$width <- 300
    a$params$height <- 300
    a$data(x)
    a
  }) 
  output$chart2 <- renderChart2({ 
    value <- as.character(input$Select2)
    x2 <- data.frame(x = c(100:105), 
                     y = c(rep("First",times = 3),rep("Second",times = 3)))
    x2 <- x2[x2$y == value,]
    b <- rCharts::Highcharts$new()
    b$chart(type = "column")
    b$data(x2)
    b$params$width <- 1200
    b$params$height <- 600
    b
  })
})

How it is achieved that the graph displays correctly.

Community
  • 1
  • 1
Peter
  • 66
  • 4

1 Answers1

2

One more day, and I found the answer by myself. I hope it will help others.

In the code, the following lines should be replaced:

a$chart(type = "column")
a$params$width <- 300
a$params$height <- 300

To:

a$chart(type = "column", height = 300, width = 300)

And it works.

Peter
  • 66
  • 4