通过单击"绘图数据点"在"闪亮"中过滤数据



我想像在powerbi中一样,通过点击Shiny中的绘图数据点来过滤数据。我在powerbi中开发了一个仪表板,我想在shine中有同样的效果,就像如果我在shine dashboard中单击plot的数据点,其他plot应该根据该点向下钻取,我已经在shine中构建了一个完整的仪表板,但我需要添加这些功能。也可以有多个数据点向下钻取,比如如果我想知道John(datapoint(2月份的销售额。

在UI中,您应该添加、单击、双击或悬停:

plotOutput("plot1", click = "plot_click")

在服务器中输入$plot_click,X和Y坐标

这里有一个精辟的解释:https://shiny.rstudio.com/articles/plot-interaction.html

我为你写了一个简单的例子:

library(shiny)
library(ggplot2)
library(MASS)
ui<- shinyUI(
fluidPage(
plotOutput("grafica", hover="clickGrafica"),    
tableOutput("miverbatini")                      
)
)
server<- shinyServer(function(input,output) {
output$grafica <- renderPlot({
ggplot(mpg,aes(x=cty, y=hwy)) +   
geom_point()
})
output$miverbatini <- renderTable({  
nearPoints(mpg,input$clickGrafica, threshold = 10)  # near points 20  
})
})
shinyApp(ui, server)

最新更新