【问题标题】:rChart opens new window in shiny applicationrChart 在闪亮的应用程序中打开新窗口
【发布时间】:2013-11-07 05:15:47
【问题描述】:

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

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

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

ui.R

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      

【问题讨论】:

    标签: r shiny rcharts rstudio-server


    【解决方案1】:

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

    这里是 rCharts 包描述中所有可用库的list

    datatables
    dimple
    highcharts
    leaflet
    morris
    nvd3
    polycharts
    rickshaw
    vega
    xcharts
    

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

    ui.R

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

    【讨论】:

      【解决方案2】:

      您在showOutput 中缺少library 的名称。如果你安装了rChartsdev分支,那么你可以运行下面的代码

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

      【讨论】:

        猜你喜欢
        • 2017-09-28
        • 2014-11-06
        • 2013-07-04
        • 2015-07-08
        • 1970-01-01
        • 2017-07-10
        • 1970-01-01
        • 2013-09-27
        • 2012-10-28
        相关资源
        最近更新 更多