【问题标题】:rCharts - combine two rCharts like gvisMergerCharts - 合并两个 rCharts,例如 gvisMerge
【发布时间】:2014-01-28 17:41:04
【问题描述】:

无论如何,我可以合并两个 rCharts,例如 gvisMerge(obj1, obj2)。我意识到 rCharts 对象是函数。有什么方法可以组合 R 函数。我正在使用一个闪亮的应用程序,我想在其中呈现两个 rCharts。

 output$chart = renderChart({
 a <- rHighcharts:::Chart$new()
 a$title(text = "Report 1")
 a$xAxis(categories = as.character(df1$Date))
 a$yAxis(title = list(text = "Report 1"))

 a$data(x = df1$Date, y = df1$Val1, type = "line", name = "Values 1")
 a$data(x = df1$Date, y = df1$Val2, type = "column", name = "Values 2")
 a

 b <- rHighcharts:::Chart$new()
 b$title(text = "Report 2")
 b$xAxis(categories = as.character(df2$Week))
 b$yAxis(title = list(text = "Report 2"))

 b$data(x = df2$Week, y = df2$Val3, type = "line", name = "Values 3")
 b$data(x = df2$Week, y = df2$Val4, type = "column", name = "Values 4")
 b
 return(a,b) # Can we combine both and return
 })

在ui.R中

output$mytabs = renderUI({
  tabs = tabsetPanel(
         tabPanel('Plots', h4("Plots"), chartOutput("chart"))
  })

【问题讨论】:

    标签: r merge shiny rcharts


    【解决方案1】:

    如果您使用 Shiny,我建议您使用其布局功能来布局您的页面,然后将图表放置在您想要的位置。这是一个最小的示例(您必须正确设置图表的宽度以避免重叠)

    library(shiny)
    library(rCharts)
    
    runApp(list(
      ui = fluidPage(
        title = 'Multiple rCharts',
        fluidRow(
          column(width = 5, chartOutput('chart1', 'polycharts')),
          column(width = 6, offset = 1, chartOutput('chart2', 'nvd3'))
        )
      ),
      server = function(input, output){
        output$chart1 <- renderChart2({
          rPlot(mpg ~ wt, data = mtcars, type = 'point')
        })
        output$chart2 <- renderChart2({
          nPlot(mpg ~ wt, data = mtcars, type = 'scatterChart')
        })
      }
    ))
    

    【讨论】:

    • 感谢您的回答,但我只想通过一个输出发送。我也在使用 rHighcharts。现在我在我的问题中添加了示例数据。
    • 没有。 renderChart 只返回一个对象。有什么理由只想发送一个输出,而发送任意数量的输出是微不足道的?其次,rHighcharts的功能已经被rCharts吸收,未来的发展将在rCharts进行。
    • 原因是我也在从 server.R 渲染选项卡,我想在一个选项卡中发送多个图。请让我知道是否有任何其他方法。很高兴听到 rCharts 中包含该功能。如果您还可以包含类似highcharts.com/demo/column-drilldown 的向下钻取工具,那就太好了
    • 向下钻取需要明确编码 javascript。可能有一种方法可以抽象出计算,但看起来并不简单。
    猜你喜欢
    • 1970-01-01
    • 2015-06-02
    • 2015-08-22
    • 1970-01-01
    • 2013-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多