RCharts of different sizes for two charts in the Shiny app
I am trying to include in my shiny app two charts (rCharts, highcharts) with different sizes, but when I change the input to the first chart, it immediately takes the size of the second.
I have been trying to find an answer in the last few days with no success. Similar question, but no answer: this Another one: this
The information in the discussion here doesn't work for me. Although, perhaps I was wrong somewhere.
Here's 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 correct display of the graph is achieved.
+3
source to share