R:rCharts和Shiny:人力车情节不会显示

use*_*259 5 r rickshaw shiny rcharts

在使用ggplot2获得闪亮的基本功能之后,我正在尝试使用rCharts.但是,我无法显示人力车图.任何帮助非常感谢; 放轻松 - 我只是习惯了这个;)

### ui

library(shiny)
require(devtools)
install_github('rCharts', 'ramnathv')
# moved from lower down so call to `showOutput` would not fail
library(rCharts) 
library(rattle)

shinyUI(

  pageWithSidebar(

  headerPanel("Rickshaw test"),

    sidebarPanel(

      selectInput("variable", 
                  "Choice is arbitrary:",
                  c("Choice 1", "Choice 2")
                  )
      ),  

  mainPanel(

    showOutput("plot", "Rickshaw")
    )
  )
)

### server


data(weather)
w = weather

dateToSeconds = function (date) {

  date = as.POSIXct(as.Date(date), origin = "1970-01-01")
  as.numeric(date)
}

w$Date = dateToSeconds(w$Date)

shinyServer(function(input, output) {

  output$mpgPlot = renderChart({

    rs = Rickshaw$new()    
    rs$layer(MinTemp ~ Date,
             data = w,
             type = "line")    
    return(rs)    
  })  
})
Run Code Online (Sandbox Code Playgroud)

Ram*_*ath 2

主要问题是showOutputrenderChartShiny 调用都需要引用相同的绘图 id。我根据这个修改了你的代码并且它有效。下面是代码供大家参考

更新。请确保您已从 github 安装了最新版本的 rCharts。

## server.R
library(shiny)
library(rCharts) 
library(rattle)
data(weather)
w = weather

dateToSeconds = function (date) {
  date = as.POSIXct(as.Date(date), origin = "1970-01-01")
  as.numeric(date)
}

w$Date = dateToSeconds(w$Date)
shinyServer(function(input, output) {

  output$plot = renderChart({  
    rs = Rickshaw$new()    
    rs$layer(MinTemp ~ Date, data = w, type = "line")
    rs$set(dom = "plot")
    return(rs)    
  })  
})

## ui.R
library(shiny)
library(rCharts) 
library(rattle)

shinyUI(pageWithSidebar(
  headerPanel("Rickshaw test"),
  sidebarPanel(
    selectInput("variable", "Choice is arbitrary:",
      c("Choice 1", "Choice 2")
    )
  ),  
  mainPanel(    
   showOutput("plot", "Rickshaw")
  )
))
Run Code Online (Sandbox Code Playgroud)