我正试图在一个闪亮的应用程序中添加一个rCharts输出。如果输入无效,那么我就不想输出任何东西--所以我希望能够返回NULL,或者在输出中有一个“空图”。但我不知道如何在rCharts中创建一个空的地块。
下面是我的代码,这个例子是直接从自述文件中取出来的,但是我注释掉了绘图代码,然后返回NULL
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)发布于 2016-11-24 18:37:17
showOutput期望一个对象返回正确,所以为什么要返回该类的空对象。
output$myChart <- renderChart({
mychart <- Polycharts$new()
return(mychart)
})https://stackoverflow.com/questions/40790436
复制相似问题