2014-11-06 35 views
1

所以我想用rCharts構建一個Shiny應用程序。當我運行下面的代碼(下面)時,我沒有得到任何錯誤,邊欄面板滾動條顯示,但barplot本身沒有生成。 (如果我只是從R Studio運行nPlot()函數,它工作正常)。rCharts和Shiny - 情節不​​顯示

server.R:同時使用 'renderChart' 與 'PT $組(DOM = myChart)' 行,和 'renderChart2'

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

伊夫試圖用AND沒有'pt $ set(dom = myChart)'行,但這兩個選項都不起作用。

謝謝!

回答

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

+0

哇哦,哈哈。我覺得我好笨。謝謝! – 2014-11-07 14:14:17

+0

樂意幫忙。容易犯錯。 – jdharrison 2014-11-07 14:14:40

+1

我有同樣的問題,但我將renderChart更改爲renderChart2,它適用於我。 – huangli 2015-11-06 08:53:55