我正在尝试编写一个小应用程序,允许用户制作散点图,在图上选择点的子集,然后输出.csv格式的表,只有那些选定的点.我想出了如何启动和运行页面以及如何使用brushedPoints选择点.出现带有所选点的表格,但是当我按下"下载"按钮时,出现错误"不允许从shinyoutput对象中读取对象".出现.我无法下载可以在屏幕上以.csv直观显示的表格吗?如果是这样,有解决方法吗?
我使用下面的虹膜数据集重新创建了这个问题.任何帮助搞清楚为什么我无法下载显示的行表将非常感激.
data(iris)
ui <- basicPage(
plotOutput("plot1", brush = "plot_brush"),
verbatimTextOutput("info"),mainPanel(downloadButton('downloadData', 'Download'))
)
server <- function(input, output) {
output$plot1 <- renderPlot({
ggplot(iris,aes(x=Sepal.Width,y=Sepal.Length)) +
geom_point(aes(color=factor(Species))) +
theme_bw()
})
output$info <- renderPrint({
brushedPoints(iris, input$plot_brush, xvar = "Sepal.Width", yvar = "Sepal.Length")
})
output$downloadData <- downloadHandler(
filename = function() {
paste('SelectedRows', '.csv', sep='') },
content = function(file) {
write.csv(output$info, file)
}
)
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)