无法通过闪亮的rCharts显示散点图

时间:2015-07-25 11:16:39

标签: r shiny rcharts

嗨:我想通过闪亮的rCharts绘制散点图,但是当我运行闪亮的应用时它无法显示。如果我运行服务器代码a <- hPlot(x="Petal.Length",y="Petal.Width",data = iris.new,type = "scatter"),则绘图显示。我该如何解决这个问题?

UI:

#ui.r

    library(shiny)
    shinyUI(fluidPage(
       titlePanel("iris data for bootstrap rcharts layout test"),
       sidebarLayout
       (
          sidebarPanel
          (
          selectInput("sp",label="choose iris species",choices=c("all","setosa","versicolor","virginica"))
          ),

          mainPanel
          (
          navbarPage(
             title="",
             tabPanel("iris_raw",dataTableOutput("table")),
             tabPanel("scatter_plot",showOutput("scatter","highcharts"),showOutput("scatter2","highcharts")
             )) 
          )
       )
                     )
             )

服务器

#server.r
library(shiny)
library(rCharts)
shinyServer(function(input, output) {
   output$table <- renderDataTable({ 
      iris.new=iris
      if(input$sp!="all") {iris.new=iris[which(iris$Species==input$sp),]}
      iris.new
   })

   output$scatter=renderChart( #draw relationship between Sepal.Length & Sepal.Width
      {
         iris.new=iris
         if(input$sp!="all") {iris.new=iris[which(iris$Species==input$sp),]}
         a <- hPlot(x="Petal.Length",y="Petal.Width",data = iris.new,type = "scatter")
         a

      }
   )
   output$scatter=renderChart( #draw relationship between Petal.Length & Petal.Width
      {
         iris.new=iris
         if(input$sp!="all") {iris.new=iris[which(iris$Species==input$sp),]}
         a <- rPlot(x="Petal.Length",y="Petal.Width",data = iris.new[which(iris.new$Species==input$sp),],type = "point")
         a
      }
   )
      }
   )

1 个答案:

答案 0 :(得分:0)

直接来自@ramnathv:

renderChart2是renderChart的修改版本。虽然renderChart直接在闪亮的输入div上创建图表,但renderChart2使用闪亮的输入div作为包装器并向其附加新的图表div。这有利于能够在闪亮和非闪亮的应用程序中保持图表创建工作流程相同

也许您应该尝试使用renderChart2而不是renderChart。