Shiny + GGplot - 鼠标点击坐标

时间:2015-06-11 12:53:51

标签: ggplot2 shiny rstudio

我对闪亮的GGPlot条形图有疑问。 我可以识别鼠标点击的坐标(x,y),但是我需要知道bar(x轴)的值以使用参数刷新图形并模拟向下钻取。 有人可以帮帮我吗?

library(shiny)
library(ggplot2)

ui <- fluidPage(
  plotOutput("plot", click = "GGPlot_click")
)

server <- function(input, output, session) {
  v <- reactiveValues(
    click1 = NULL  
  )

  # Handle clicks on the plot
  observeEvent(input$GGPlot_click, {
      v$click1 <- input$GGPlot_click
  })

  observeEvent(input$reset, {
    v$click1 <- NULL
  })

  output$plot <- renderPlot({
    pg <- ggplot(cars, aes(speed, dist)) +  geom_bar(stat="identity")

    print(pg)
    if (!is.null(v$click1$x))
      print(paste(v$click1$x, v$click1$y, sep = " / "))
      #print(v$click1)
  })
}

shinyApp(ui, server)

图片和代码:https://github.com/faustobranco/stackquestion

1 个答案:

答案 0 :(得分:1)

我找到了解决问题的方法:

图片和代码:https://github.com/faustobranco/StackQuestions

 Private Sub cmdSRSend_Click()

 Dim MyPath As String
 Dim MyFile As String
 Dim LatestFile As String
 Dim LatestDate As Date
 Dim LMD As Date



 'Specify the path to the folder
 MyPath = "https://ts.company.com/sites/folder1/folder2/00%20Admin/Shift%20Record/"

 'Make sure that the path ends in a backslash
 If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"

 'Get the first Excel file from the folder
 MyFile = Dir(MyPath & "MANILA_ShiftRecord_2015*.xlsx", vbNormal)

 'If no files were found, exit the sub
 If Len(MyFile) = 0 Then
 MsgBox "No files were found...", vbExclamation
 Exit Sub
 End If

 'Loop through each Excel file in the folder
 Do While Len(MyFile) > 0

 'Assign the date/time of the current file to a variable
 LMD = FileDateTime(MyPath & MyFile)

 'If the date/time of the current file is greater than the latest
 'recorded date, assign its filename and date/time to variables
 If LMD > LatestDate Then
 LatestFile = MyFile
 LatestDate = LMD
 End If

 'Get the next Excel file from the folder
 MyFile = Dir

 Loop

 'Open the latest file
 Workbooks.Open MyPath & LatestFile



 End Sub
相关问题