如何通过水管工Web API返回ggvis或rcharts图

时间:2018-07-19 15:18:53

标签: r api rcharts ggvis plumber

因此,我跟管道工文档一起:

# plumber.R

#' Echo the parameter that was sent in
#' @param msg The message to echo back.
#' @get /echo
function(msg=""){
  list(msg = paste0("The message is: '", msg, "'"))
}

#' Plot out data from the iris dataset
#' @param spec If provided, filter the data to only this species (e.g. 'setosa')
#' @get /plot
#' @png
function(spec){
  myData <- iris
  title <- "All Species"

  # Filter if the species was specified
  if (!missing(spec)){
    title <- paste0("Only the '", spec, "' Species")
    myData <- subset(iris, Species == spec)
  }

  plot(myData$Sepal.Length, myData$Petal.Length,
       main=title, xlab="Sepal Length", ylab="Petal Length")
}

并使用http://localhost:8000/plot或任何端口,都可以正常工作。

现在,当我尝试使用ggvis或rcharts绘制数据时,在浏览器中出现一个空白屏幕。我已经在plumber.R api scrip btw中加载了所需的软件包。

 # Filter if the species was specified
  if (!missing(spec)){
    myData <- subset(iris, Species == spec)
  }

  myData %>% ggvis(~SepalLength,~SepalWidth, fill=~Species) %>% layer_points()


}

这也不起作用。

  # Filter if the species was specified
  if (!missing(spec)){
    myData <- subset(iris, Species == spec)
  }

  rPlot(SepalLength~SepalWidth|Species,data=myData,color = 'Species', type = 'point')

}

是否有可能,或者我错过了一些非常琐碎的事情。

0 个答案:

没有答案