rCharts和Shiny - 情节没有显示出来

时间:2014-11-06 21:11:59

标签: r shiny rcharts shiny-server

所以我试图用rCharts构建一个Shiny应用程序。当我运行以下代码(下面)时,我没有错误,侧边栏面板滚动条显示,但是没有生成条形图本身。 (如果我只是从R Studio运行nPlot()函数,它工作正常)。

server.R:

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

ui.R

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

我尝试过使用&#39; renderChart&#39;使用&#39; pt $ set(dom = myChart)&#39; line,&#39; renderChart2&#39;使用AND而没有&#39; pt $ set(dom = myChart)&#39;但是,这两种选择都不起作用。

谢谢!

1 个答案:

答案 0 :(得分:7)

您正在链接到不正确的库。 nPlotnvd3,而不是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")
    )
  )
  )
)

enter image description here