簡體   English   中英

閃亮的交互式圖顯示行名

[英]Shiny Interactive Graph plot showing row names

我正在使用Shiny和ggplot2進行交互式圖形顯示。 我還使用“ plot1_click”獲取x和y位置。

output$selected <- renderText({
paste0("Value=", input$plot1_click$x, "\n",
       "Names=", input$plot1_click$y)  }) #how to get names???

這是服務器代碼的一部分。 我要的是,而不是打印“ y”坐標,而是要打印在y軸上寫的相應名稱。 有什么可能的辦法嗎?

據我所知, plotOutput不支持單擊點。 點擊事件只會返回點擊位置的坐標。 但是,這些坐標可用於找出最近的點。

這個來自閃亮圖庫頁面的閃亮應用程序使用了shiny::nearPoints函數,它可以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。 但是幫助頁面建議,還有一種將其用於基本圖形的方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM