-1

hi: I want to draw the scatter plot by rCharts in shiny, but it can't show when I run the shiny app. If I run the server code a <- hPlot(x="Petal.Length",y="Petal.Width",data = iris.new,type = "scatter") , the plot shows. How should I fix this problem?

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:

#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
      }
   )
      }
   )
swchen
  • 643
  • 2
  • 8
  • 24

1 Answers1

0

Directly from @ramnathv:

renderChart2 is a modified version of renderChart. While renderChart creates the chart directly on a shiny input div, renderChart2 uses the shiny input div as a wrapper and appends a new chart div to it. This has advantages in being able to keep chart creation workflow the same across shiny and non-shiny applications

Maybe you should try using renderChart2 instead of renderChart.

susacb
  • 11
  • 4