【发布时间】:2016-01-06 21:13:18
【问题描述】:
我正在尝试创建一个界面,从下拉菜单中选择 x 和 y 变量后,用户可以观察散点图,并使用画笔选择点。这些点的数据将显示在数据表中。 这在静态图上非常有效,其中 x 和 y 变量不会改变。但是,当 x 和 y 变量的选择是输入选项的结果时,虽然绘图正常工作,但画笔似乎无法正确读取数据。
它不会让我上传图像,但是当您检查画笔输出的文本时,x 和 y 值的范围为 0-1,当您可以读取轴标签的实际值时,范围为0-7。所以我显然没有正确设置画笔。 数据表中出现一条错误消息,显示“错误:brushedPoints:无法从画笔自动推断“xvar”
ui<-fluidPage(
fluidRow(
column(4,selectInput("X_axis_Category",label="X axis Category",choices=as.list(colnames(scores_test)),selected="Ecological_Stress")
),
column(4,selectInput("Y_axis_Category",label="Y axis Category",choices=as.list(colnames(scores_test)),selected="Ecological_Health")
),
column(4,selectInput("Z_axis_Category",label="Z axis Category",choices=as.list(colnames(scores_test)),selected="Comprehensive_Score")
),
column(12, plotOutput("plotui",brush=brushOpts("plot_brush",resetOnNew=T))),
column(12,verbatimTextOutput("brush_info")),
wellPanel(width=9,h4("Points selected by brushing, with brushedPoints():"),dataTableOutput("plot_brushed_points"))
)
)
server<-function(input,output){
sample_scores=read.csv(file="D:\\GIS Projects\\TreesforTribs\\HUC12_Watershed_Scores.csv",sep=",")
dat<-sample_scores
x_means<-reactive({
mean(sample_scores[,input$X_axis_Category])
})
y_means<-reactive({
mean(sample_scores[,input$Y_axis_Category])
})
x_var<-reactive({
as.character(input$X_axis_Category)
})
y_var<-reactive({
as.character(input$Y_axis_Category)
})
output$plotui= renderPlot({
pc<-ggplot(sample_scores,aes_string(x=input$X_axis_Category,y=input$Y_axis_Category,size=input$Z_axis_Category,colour=input$Z_axis_Category))+ geom_point()+geom_vline(xintercept=x_means())+geom_hline(yintercept=y_means()) +
guides(color=guide_legend(),size=guide_legend())
print (pc)
})
output$plot_brushed_points<-renderDataTable({
res<-brushedPoints(dat,input$plot_brush)
subset_res<-subset(res,select=c(HUC12,Ecological_Health,Ecological_Stress,Comprehensive_Score))
print (subset_res)
})
output$brush_info<-renderPrint({
cat("input$plot_brush:\n")
str(input$plot_brush)
})
}
【问题讨论】:
-
如果可能,提供可重现的代码,包括一些示例数据
标签: r ggplot2 shiny interactive