r与Highcharts一起作为闪亮的应用程序 [英] rCharts with Highcharts as shiny application

查看:131
本文介绍了r与Highcharts一起作为闪亮的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  require(shiny)
require(rCharts )
runApp(shinyApp)

应用程序启动,但情节不可见。它使用正常的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 = )
h1 $ series(data = c(NA,4,1,3,4),dashStyle =shortdot)
h1 $ legend(symbolWidth = 80)
return( h1)
})
})

ui.R:

  require(rCharts)
shinyUI(pageWithSidebar(
headerPanel(rCharts:Highcharts)),
sidebarPanel(
selectInput(inputId =x,
label =选择X,
选择= c('SepalLength','SepalWidth','PetalLength','PetalWidth'),
selected =SepalLength)
),
mainPanel(showOutput(myChart,Highcharts)

))

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

解决方案

如何使这个工作。第一种方法是在 server.R 中添加 h1 $ set(dom =myChart)。这是必需的,以便 server.R ui.R 正在传达有关正确图表的信息。另一种方法是使用 renderChart2 ,它位于 rCharts dev 分支中c $ c>,这是 renderChart 的升级版本,并且最终将替换它。

  require(rCharts)
require(shiny)
runApp(list(
ui = pageWithSidebar(
headerPanel(rCharts:Highcharts)),
sidebarPanel(selectInput(
inputId =x,
label =选择X,
选择= c('SepalLength','SepalWidth','PetalLength','PetalWidth'),
selected =SepalLength
)),
mainPanel (showOutput(myChart,Highcharts))
),
server = function(输入,输出){
输出$ 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)
})
}
))


I have a shiny application consisting of three files. server.R, ui.R and the file to launch the application with

require(shiny)
require(rCharts)
runApp("shinyApp")

The application starts, but the plot is not visible. It works with a normal r-plot and with polycharts, but after trying a lot, I still have no success with rCharts (which includes rHighcharts).

This is the files of the last try:

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)
  })
})

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")
  )
))

My assumption is that the second argument of "showOutput" might be wrong, but I didn't find anything.

解决方案

There are two ways to get this working. The first way is to add h1$set(dom = "myChart") in your server.R. This is required so that both server.R and ui.R are communicating about the correct chart. The alternative is to use renderChart2, which is in the dev branch of rCharts, that is a upgraded version of renderChart and will eventually replace it. I am attaching the entire code for everyone's benefit.

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)
    })
  }
))

这篇关于r与Highcharts一起作为闪亮的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆