javascript - 通过单击 Plot Data Point 在 Shiny 中过滤数据
问题描述
我想通过单击 Shiny 中的绘图数据点来过滤数据,就像我们在 powerbi 中一样。我已经在powerbi中开发了一个仪表板我希望在闪亮时具有相同的效果,例如如果我单击闪亮仪表板中的绘图数据点,其他绘图应该向下钻取以响应该点,我已经在闪亮中构建了一个完整的仪表板但是我需要添加这些功能。如果我想知道约翰(数据点)的 2 月(数据点)月销售额,也可以有多个数据点向下钻取。
解决方案
在 UI 中,您应该添加、单击、双击或悬停:
plotOutput("plot1", click = "plot_click")
并且在Server中会输入$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)
推荐阅读
- django - 在 django 过滤器中搜索有无空格
- android - 将自定义数据从 Firebase 云消息传递控制台显示到 Flutter 应用程序?
- c# - 异步等待死锁?
- java - java中比较器的问题
- android - Android Kotlin - 如何将主活动类中的名称函数分配给另一个类中的 setOnClickListener?
- c# - C# - 如何在 Amadeus API 上发送 SOAP 请求
- java - 命名空间“classloader-namespace”无法访问库
- php - 如何使用 FPDF 为特定 id 从 mySQL 表生成 pdf 发票
- excel - Excel 的 MATCH 和 TIME 公式问题
- css - CSS 特殊形状,带有一个光角