6

我正在尝试在闪亮的应用程序中绘制 rChart 并通过 Rstudio 服务器运行它。当我运行该应用程序时,闪亮的页面会出现错误:尝试应用非功能并且 RChart 在新的浏览器窗口中打开。

如何让 rChart 出现在闪亮的应用程序中?

服务器.R

library(shiny)
require(rCharts)

names(iris) = gsub("\\.", "", names(iris))

shinyServer(function(input, output) {

output$myChart  <- renderChart({
h1 <- hPlot(x = "Wr.Hnd", y = "NW.Hnd", data = MASS::survey, 
type = c("line", "bubble", "scatter"), group = "Clap", size = "Age")
return(h1$show(cdn = TRUE))
  })
})

用户界面

library(shiny)
require(rCharts)
shinyUI(pageWithSidebar(

headerPanel("rCharts and shiny"),

sidebarPanel(),

mainPanel(
showOutput("myChart")
  )
))

我的 R 会话信息

R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)

other attached packages:
[1] shiny_0.7.0     plyr_1.8        rCharts_0.3.51  devtools_1.3    ggplot2_0.9.3.1    RMySQL_0.9-3    DBI_0.2-7      
4

2 回答 2

8

您必须根据您使用的绘图类型指定需要导入的库。

这是 rCharts 包描述中所有可用库的列表

datatables
dimple
highcharts
leaflet
morris
nvd3
polycharts
rickshaw
vega
xcharts

这是 rcharts 网站上的演示代码,我对其进行了修改以绘制 hplot。

用户界面

require(rCharts)
shinyUI(pageWithSidebar(
  headerPanel("rCharts: Interactive Charts from R using highcharts"),

  sidebarPanel(
    selectInput(inputId = "x",
                label = "Choose X",
                choices = c('SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'),
                selected = "SepalLength"),
    selectInput(inputId = "y",
                label = "Choose Y",
                choices = c('SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'),
                selected = "SepalWidth")
  ),
  mainPanel(
    showOutput("myChart", "highcharts")
  )
))

服务器.R

require(rCharts)
shinyServer(function(input, output) {
  output$myChart <- renderChart({
    names(iris) = gsub("\\.", "", names(iris))
    # HPLOT
    p1 <- hPlot(input$x, input$y, data = iris, type = c("line", "bubble", "scatter"), group = "Species", size = 1)
    # RPLOT
    #p1 <- rPlot(input$x, input$y, data = iris, color = "Species", facet = "Species", type = 'point')
    p1$addParams(dom = 'myChart')
    return(p1)
  })
})

在此处输入图像描述

于 2013-10-29T02:38:12.627 回答
7

您缺少libraryin的名称showOutput。如果安装 的dev分支rCharts,则可以运行以下代码

library(shiny)
# devtools::install_github("rCharts", "ramnathv", ref = "dev")
library(rCharts)
runApp(list(
  ui = pageWithSidebar(
    headerPanel("rCharts and shiny"),
    sidebarPanel(

    ),
    mainPanel(
      showOutput("myChart", "highcharts")
  )),
  server = function(input, output, session){
    output$myChart  <- renderChart2({
      h1 <- hPlot(x = "Wr.Hnd", y = "NW.Hnd", data = MASS::survey, 
        type = c("line", "bubble", "scatter"), group = "Clap", 
        size = "Age"
      )
      return(h1)
    })
  }
))
于 2013-10-29T02:26:01.357 回答