So I am trying to build a Shiny app with rCharts. When I run the following code (below) I get no errors and the sidebar panel scrollbar shows, but the barplot itself is not generated. (It works fine if I just run the nPlot() function from R Studio).
require(rCharts)
require(shiny)
# random data:
smpl<-data.frame(gene = c("gene1","gene2","gene3","gene4","gene5",
"gene6","gene7","gene8","gene9","gene10"),
direction = c("up","down","up","up","up",
"up","up","down","down","down"),
type = c("norm","norm","tum","tum","norm",
"tum","tum","norm","tum","tum"),
foldChange = c(1.3, 0.4, 1.3, 3.0, 1.6,
2.9, 1.3, 0.5, 0.5, 0.6))
shinyServer(function(input, output) {
output$myChart <- renderChart({
n <- subset(smpl, type == input$x)
p1 <- nPlot(foldChange ~ gene, group = "direction", n,
type = 'multiBarChart')
p1$set(dom = 'myChart')
return(p1)
})
})
require(rCharts)
require(shiny)
shinyUI(pageWithSidebar(
headerPanel("Sample Bar Plot"),
sidebarPanel(
selectInput(inputId = "x",
label = "Select:",
choices = c("norm","tum"),
selected = "norm")
),
mainPanel(
showOutput("myChart", "polycharts")
)
))
Ive tried using both 'renderChart' with the 'pt$set(dom = myChart)' line, and 'renderChart2' with AND without the 'pt$set(dom = myChart)' line, but neither option works.
Thanks!
You are linking to an incorrect library. nPlot
is nvd3
rather then polychart
:
require(rCharts)
require(shiny)
smpl<-data.frame(gene = c("gene1","gene2","gene3","gene4","gene5",
"gene6","gene7","gene8","gene9","gene10"),
direction = c("up","down","up","up","up",
"up","up","down","down","down"),
type = c("norm","norm","tum","tum","norm",
"tum","tum","norm","tum","tum"),
foldChange = c(1.3, 0.4, 1.3, 3.0, 1.6,
2.9, 1.3, 0.5, 0.5, 0.6))
runApp(
list(server= function(input, output) {
output$myChart <- renderChart2({
n <- subset(smpl, type == input$x)
p1 <- nPlot(foldChange ~ gene, group = "direction", n,
type = 'multiBarChart')
# p1$set(dom = 'myChart')
return(p1)
})
}
, ui = pageWithSidebar(
headerPanel("Sample Bar Plot"),
sidebarPanel(
selectInput(inputId = "x",
label = "Select:",
choices = c("norm","tum"),
selected = "norm")
),
mainPanel(
showOutput("myChart", "nvd3")
)
)
)
)