【发布时间】:2015-07-16 04:28:35
【问题描述】:
我正在使用 ggplot2 数据集中的 Iris 数据开发 R Shiny 仪表板。 它具有三个主要组件,一个用于选择要在图中显示的变量的侧边栏面板,一个带有刷点的 ggplot 和一个显示刷点数据的数据表。 除了数据表似乎没有选择表上的数据点外,一切都运行良好。据我所知,它与服务器中的 output$plot_brushed_points 行有关。 任何帮助将不胜感激!
library(shiny)
library(ggplot2)
useri <- shinyUI(pageWithSidebar(
headerPanel("Reactive Plot"),
sidebarPanel(
selectInput('x','X-Axis',names(iris)),
selectInput('y','Y-Axis',names(iris)),
selectInput('color','Color',c('None',names(iris[5])))),
mainPanel(uiOutput("plotui"),dataTableOutput("plot_brushed_points"))))
serveri <- shinyServer(function(input,output) {
output$plot <- renderPlot({
p <- ggplot(iris,aes_string(x=input$x, y=input$y))+geom_point()+theme_bw()
if(input$color != 'None')
p <- p + aes_string(color=input$color)
print(p)
})
output$plotui <- renderUI(plotOutput("plot",brush = brushOpts("plot_brush")))
output$plot_brushed_points <- renderDataTable(brushedPoints(iris,input$plot_brush,input$x,input$y), options=list(searching=FALSE, paging = FALSE))
})
shinyApp(useri, serveri)
我应该注意到数据表显示并且您可以看到它刷新,它只是没有填充任何数据。
编辑
上面的脚本有一个功能,当且仅当您选择绘图的整个区域时,它才会显示数据表中的所有值。
【问题讨论】: