rCharts与Highcharts一起作为闪亮的应用程序

Kal*_*lle 11 r highcharts shiny rcharts

我有一个由三个文件组成的闪亮应用程序.server.R,ui.R和用于启动应用程序的文件

require(shiny)
require(rCharts)
runApp("shinyApp")
Run Code Online (Sandbox Code Playgroud)

应用程序启动,但图表不可见.它适用于正常的r-plot和polycharts,但经过多次尝试后,我仍然没有成功使用rCharts(包括rHighcharts).

这是最后一次尝试的文件:

server.R:

library(rCharts)
shinyServer(function(input, output) {
  output$myChart <- renderChart({
    h1 <- Highcharts$new()
    h1$chart(type = "spline")
    h1$series(data = c(1, 3, 2, 4, 5), dashStyle = "longdash")
    h1$series(data = c(NA, 4, 1, 3, 4), dashStyle = "shortdot")
    h1$legend(symbolWidth = 80)
    return(h1)
  })
})
Run Code Online (Sandbox Code Playgroud)

ui.R:

require(rCharts)
shinyUI(pageWithSidebar(
  headerPanel("rCharts: Highcharts"),
  sidebarPanel(
    selectInput(inputId = "x",
      label = "Choose X",
      choices = c('SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'),
      selected = "SepalLength")
    ),
  mainPanel(showOutput("myChart", "Highcharts")
  )
))
Run Code Online (Sandbox Code Playgroud)

我的假设是"showOutput"的第二个参数可能是错误的,但我没有找到任何东西.

Ram*_*ath 17

有两种方法可以实现这一点.第一种方法是添加h1$set(dom = "myChart")你的server.R.这是必需的,这样双方server.Rui.R有关正确的图表进行通信.另一种方法是使用renderChart2,它位于dev分支中rCharts,是升级版本,renderChart最终将取代它.我附上了整个代码,为每个人带来了好处.

require(rCharts)
require(shiny)
runApp(list(
  ui =  pageWithSidebar(
    headerPanel("rCharts: Highcharts"),
    sidebarPanel(selectInput(
      inputId = "x",
      label = "Choose X",
      choices = c('SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'),
      selected = "SepalLength"
    )),
    mainPanel(showOutput("myChart", "Highcharts"))
  ),
  server = function(input, output){
    output$myChart <- renderChart2({
      h1 <- Highcharts$new()
      h1$chart(type = "spline")
      h1$series(data = c(1, 3, 2, 4, 5), dashStyle = "longdash")
      h1$series(data = c(NA, 4, 1, 3, 4), dashStyle = "shortdot")
      h1$legend(symbolWidth = 80)
      return(h1)
    })
  }
))
Run Code Online (Sandbox Code Playgroud)