클릭 지점을 알고있는 한 plotOutput
에는 지원되지 않습니다. 클릭 이벤트는 클릭 위치의 좌표 만 반환합니다. 그러나 이러한 좌표는 가장 가까운 점을 파악하는 데 사용될 수 있습니다.
This shiny app 반짝이 갤러리 페이지에서 정확히 기능을 수행하는 shiny::nearPoints
을 사용합니다. 다음은 최소한의 예입니다.
library(shiny)
library(ggplot2)
shinyApp(
fluidPage(
plotOutput("plot", click = "plot_click"),
verbatimTextOutput('print')
),
server = function(input, output, session){
output$plot <- renderPlot({ggplot(mtcars, aes(wt, mpg)) + geom_point()})
output$print = renderPrint({
nearPoints(
mtcars, # the plotting data
input$plot_click, # input variable to get the x/y coordinates from
maxpoints = 1, # only show the single nearest point
threshold = 1000 # basically a search radius. set this big enough
# to show at least one point per click
)
})
}
)
verbatimTextOutput
에는 가장 가까운 클릭 지점이 표시됩니다. nearPoints
은 그런 ggplots에서만 작동합니다. 그러나 도움말 페이지에는 기본 그래픽과 함께 사용하는 방법이 있음을 알 수 있습니다.
이것은 약간의 회피책이지만, 플롯하기 위해 사용했던 데이터 프레임에 x와 y 좌표가 있다고 가정하면'Names = ", data $ name [data $ x == input $ plot1_click $ x & data $ y == 입력 $ plot1_click $ y]' – KGee