Reputation: 523
Are there any restrictions on using hPlot
(vs hist
) in shiny? I could not find any info about restrictions on using rCharts stuff on shiny. Not sure what I'm missing.
I really need/want to use hPlot to make better presentation.
## ui.R
library(shiny)
library(rCharts)
shinyUI(fluidPage(
titlePanel("Count Report "),
h4("This application shows product data"),
sidebarLayout(
sidebarPanel(
selectizeInput("product","Product:",c("ALPHA","BRAVO","all"), selected="all")
),
mainPanel(
h4("rChart Auuuuu??????!!!"),
plotOutput("chart")
)
)
))
##---server.R
library(shiny)
library(rCharts)
shinyServer(
function(input, output) {
x <- data.frame(Category=factor(c("ALPHA", "ALPHA","BRAVO","ALPHA","ALPHA")),
YYYYMM= factor(c("2/1/2015","3/1/2015","4/1/2015","5/1/2015","6/1/2015")),
COUNT=c(44,22,37,76,97))
output$chart <- renderPlot({
# generate an rnorm distribution and plot it
#hist(x$COUNT) ######### this works OK
hPlot(COUNT ~ YYYYMM, data=x, type="line") ######### doesnt WORK!
})
})
Upvotes: 1
Views: 153
Reputation: 29407
Please note the changes I made where I used showOutput
instead of plotOutput
and renderChart2
instead of renderPlot
as you need to make* these changes to make rChart
plots. Also you need to specify namespace in the showOutput
, I think that hplot
belongs to highcharts
but I might be wrong (if anyone knows for sure feel free to comment here so I can update the answer). For more information about using rCharts
you can look at the examples here on github.
The following should work:
rm(list = ls())
library(shiny)
library(rCharts)
ui <- fluidPage(
titlePanel("Count Report "),
h4("This application shows product data"),
sidebarLayout(
sidebarPanel(
selectizeInput("product","Product:",c("ALPHA","BRAVO","all"), selected="all")
),
mainPanel(
h4("rChart works!"),
showOutput("chart", "highcharts")
)
)
)
server <- function(input, output) {
x <- data.frame(Category=factor(c("ALPHA", "ALPHA","BRAVO","ALPHA","ALPHA")),
YYYYMM= factor(c("2/1/2015","3/1/2015","4/1/2015","5/1/2015","6/1/2015")),
COUNT=c(44,22,37,76,97))
output$chart <- renderChart2({
a <- hPlot(COUNT ~ YYYYMM, data=x, type="line") ######### doesnt WORK!
return (a)
})
}
shinyApp(ui, server)
Upvotes: 1