2016-11-24 4 views
0

빛나는 응용 프로그램에 rCharts 출력을 추가하려고합니다. 입력이 유효하지 않다면 아무 것도 출력하고 싶지 않습니다. 따라서 NULL을 반환하거나 출력에 "빈 플롯"이 생기고 싶습니다. 하지만 rCharts에서 빈 줄거리를 만드는 방법을 알아낼 수는 없습니다. 여기 rCharts에서 빈 플롯을 만드는 방법은 무엇입니까?

는 예를 똑바로 README에서 촬영, 내가 가지고있는 코드입니다하지만 플롯 코드에서 주석 대신

library(shiny) 
library(rCharts) 

ui <- pageWithSidebar(
    headerPanel("rCharts: Interactive Charts from R using polychart.js"), 

    sidebarPanel(
    selectInput(inputId = "x", 
       label = "Choose X", 
       choices = c('SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'), 
       selected = "SepalLength"), 
    selectInput(inputId = "y", 
       label = "Choose Y", 
       choices = c('SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'), 
       selected = "SepalWidth") 
), 
    mainPanel(
    showOutput("myChart", "polycharts") 
) 
) 

server<- function(input, output) { 
    output$myChart <- renderChart({ 
    # names(iris) = gsub("\\.", "", names(iris)) 
    # p1 <- rPlot(input$x, input$y, data = iris, color = "Species", 
    #    facet = "Species", type = 'point') 
    # p1$addParams(dom = 'myChart') 
    # return(p1) 
    return(NULL) 
    }) 
} 

shinyApp(ui, server) 

답변

1

showOutput 객체가 백 우측 기대 NULL 반환, 왜 당신은 돌려주지 않는다 그 클래스의 빈 객체

output$myChart <- renderChart({ 
     mychart <- Polycharts$new() 
     return(mychart) 
}) 
+0

감사합니다. 나는 rCharts를 가진 완전한 멍청한 녀석이다. 그것은 정확하게 어떻게해야 하는지를 알 필요가있다. 감사. 나는'renderChart2'를 사용해야한다고 다른 대답을 보았습니다 - 여러분은 그 차이점을 알고 있습니까? –

+1

나는 하나 또는 다른 것을 사용할 때 솔직히 100 % 확신하지는 않는다. 일부 라이브러리에 객체를 반환해야하므로 그 객체를 다루기 위해 renderChart2와 함께 패치를 도입했지만 다시는 100 % 확실하지 않습니다. 가장 큰 차이점은 libs는'polycharts','nvd3','highcharts' 등을 사용하는 라이브러리입니다. –