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