rCharts in shiny : width with 2 charts

有些话、适合烂在心里 提交于 2019-11-30 17:29:50

问题


I have an app with two Highcharts plot, when I start the app the width of the two plots are correct, but everytime I change the mean input, the width of the first plot is set to the width of the second, like this :

When I start the app :

When I change the input :

My code to produce the app :

library(rCharts)
library(shiny)

runApp(list(
  ui = fluidPage(
    title = "App title",
    titlePanel(strong("App title", style="color: steelblue")),
    sidebarLayout(
      sidebarPanel(width = 2,
                   br()),
      mainPanel(width = 10, 
                tabsetPanel(
                  tabPanel("Tab 1",
                           selectInput(inputId = "input_mean", label = "Mean : ", choices = c(20:30)),
                           fluidRow(
                             column(8,
                                    showOutput(outputId = "chart1", lib = "highcharts")
                                    , br(), br(), br(), br(), br(), br(), br(), br(), br(), br(), br()),
                             column(4,
                                    showOutput(outputId = "chart2", lib = "highcharts"))
                             )
                           )
                  )
                )
      )
    ),
  server = function(input, output) {

    my_data <- reactive({
      rnorm(n = 30, mean = as.numeric(input$input_mean))
    })

    output$chart1 <- renderChart2({
      my_data = my_data()
      h2 <- Highcharts$new()
      h2$chart(type="line")
      h2$series(data=my_data, name = "One", marker = list(symbol = 'circle'), color = "lightblue")
      h2$set(width = 800, height = 400)
      return(h2)
    })
    output$chart2 <- renderChart2({
      my_data = my_data()
      my_mean = as.numeric(input$input_mean)
      part = data.frame(V1 = c("Sup", "Inf"), V2 = c(sum(my_data>my_mean), sum(my_data<my_mean)))
      p = hPlot(x = "V1", y = "V2", data = part, type = "pie")
      p$tooltip(pointFormat = "{series.name}: <b>{point.percentage:.1f}%</b>")
      p$params$width <- 200
      p$params$height <- 200
      return(p)
    })
  }
))

I use rCharts_0.4.5 and shiny_0.9.1.

Thanks !


回答1:


Replace these lines:

h2$chart(type="line")
h2$set(width = 800, height = 400)

as follows:

h2$chart(type="line", width = 800, height = 400)

This should help.



来源:https://stackoverflow.com/questions/26144605/rcharts-in-shiny-width-with-2-charts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!