I am developing a Shiny application and I'm having trouble when integrating with rCharts. I made a simple app with a database "Cars93" that everyone can access to exemplify my problem.
I put a table and a graph in the app, the table is only to test if the data is correct.
My problem is that the graph does not appear.
Thanks in advance!
Luis
ui.R
library(shiny)
library(MASS)
require(rCharts)
options(RCHART_LIB = 'polycharts')
mydata<-Cars93
shinyUI(pageWithSidebar(
headerPanel('RCharts - Test'),
sidebarPanel(
selectInput("Manufacturer2", "Select a Manufacturer", levels(droplevels(mydata$Manufacturer)),
selected = "Acura"
),
selectInput("Type2", "Select a Type", levels(droplevels(mydata$Type))[3:4],selected = levels(droplevels(mydata$Type))[3]
),
width = 3
),
mainPanel(
tabsetPanel(
tabPanel("Table",dataTableOutput('mytable')),
tabPanel("Chart",showOutput('myplot', 'polycharts'))
)
))
)
server.R
library(shiny)
library(rCharts)
library(MASS)
options(RCHART_WIDTH = 800)
mydata<-Cars93
data2<-Cars93
shinyServer(function(input, output, session) {
observe({
updateSelectInput(session, "Type2", choices = levels(droplevels(mydata$Type[mydata$Manufacturer %in% input$Manufacturer2])),selected = levels(droplevels(mydata$Type[mydata$Manufacturer %in% input$Manufacturer2]))[1]
)
})
output$mytable = renderDataTable({
MANUFACTURER = input$Manufacturer2
TYPE = input$Type2
mydata<- mydata[mydata$Manufacturer %in% MANUFACTURER & mydata$Type %in% TYPE,]
mydata<-mydata[,c("Manufacturer","Type","Model","Weight")]
mydata
})
output$myplot<- renderChart({
MANUFACTURER = input$Manufacturer2
TYPE = input$Type2
mydata<- mydata[mydata$Manufacturer %in% MANUFACTURER & mydata$Type %in% TYPE,]
p1<-rPlot(Weight ~ Model, color = 'Model', data = mydata, type = 'bar')
p1$guides(
color = list(
numticks = length(factor(mydata$Model))
),
y = list(
min = 0,
max = 10
)
)
return(p1)
})
})
dom
.p1$set(dom = "myplot")
inrenderChart
or userenderChart2
unstead ofrenderChart
. – jdharrison