2016-04-18 21 views
3

工作在RStudio罰款,但空使用下面rCharts:地塊閃亮的應用

library(shiny) 
library(rCharts)  
hair_eye_male <- subset(as.data.frame(HairEyeColor), Sex == "Male") 
n1 <- nPlot(Freq ~ Hair, 
      group = "Eye", 
      data = hair_eye_male, 
      type = 'multiBarChart') 
n1 

代碼我RStudio

enter image description here

得到這個情節我想創建一個閃亮的應用這個情節。我使用下面的代碼創建應用程序

library(shiny) 
library(rCharts) 
ui <- fluidPage(
    mainPanel(uiOutput("tb"))) 
server <- function(input,output){ 

    output$hair_eye_male <- renderChart({ 

    hair_eye_male <- subset(as.data.frame(HairEyeColor), Sex == "Male") 
    n1 <- nPlot(Freq ~ Hair, group = "Eye", data = hair_eye_male, 
       type = 'multiBarChart') 
    return(n1) 
    }) 
    output$tb <- renderUI({ 
    tabsetPanel(tabPanel("First plot", 
         showOutput("hair_eye_male"))) 
    }) 
} 
shinyApp(ui = ui, server = server) 

但是,閃亮的應用程序沒有渲染情節。它看起來是空的。任何建議,將不勝感激。

回答

1

當您使用rCharts軟件包時,您需要指定您正在使用的JavaScript庫。

通過添加n1$addParams(dom = 'hair_eye_male')行到renderChart()並指定您在showOutput()中使用哪個庫,代碼將起作用。

library(shiny) 
library(ggplot2) 
library(rCharts) 

ui <- fluidPage(
    mainPanel(uiOutput("tb"))) 
server <- function(input,output){ 

    output$hair_eye_male <- renderChart({ 

    hair_eye_male <- subset(as.data.frame(HairEyeColor), Sex == "Male") 
    n1 <- nPlot(Freq ~ Hair, group = "Eye", data = hair_eye_male, 
       type = 'multiBarChart') 
    n1$addParams(dom = 'hair_eye_male') 
    return(n1) 
    }) 
    output$tb <- renderUI({ 
    tabsetPanel(tabPanel("First plot", 
         showOutput("hair_eye_male", lib ="nvd3"))) 
    }) 
} 
shinyApp(ui = ui, server = server) 
+0

感謝您的時間和幫助。我使用你的代碼得到了這個錯誤 錯誤:未使用的參數(lib =「nvd3」)。 – aelwan

+0

@aelwan:我使用命令安裝了rCharts:'require(devtools) install_github('ramnathv/rCharts')' –

+0

非常感謝。現在工作正常。 – aelwan