【发布时间】:2021-10-04 10:44:05
【问题描述】:
我正在尝试制作一个应用程序,该应用程序显示与最近点关联的标签(在绘制区域上,如果可能,不在下方)悬停在散点图上。我一直无法在网上找到准确的例子,如果这个问题已经在某些地方得到解决,我们深表歉意。
这是我目前所拥有的:
df <- data.frame(x = rnorm(100), y = rnorm(100), label = paste("gene", seq(100)))
ui <- fluidPage(
plotOutput(outputId = "scatterplot", hover = "plot_hover"),
verbatimTextOutput("info")
)
server <- function(input, output) {
output$scatterplot <-
renderPlot({
ggplot(df, aes(x, y)) +
geom_point()
})
output$info <- renderPrint({
row <- nearPoints(df, input$plot_hover, threshold = 5, maxpoints = 1)
cat("Testing:\n")
print(row$label)
})
}
shinyApp(ui, server)
我应该说:我对 RShiny 很陌生。
【问题讨论】: