闪亮的悬停 - 奇怪的日期格式

时间:2017-08-08 09:10:49

标签: r date shiny

我有一个闪亮的应用程序,其中包含时间序列和悬停事件的图表,该事件输出当前悬停在值上的日期和值。奇怪的是,它输出的日期格式我无法完全指责。例如,2013-05-03变为1.369267e+12。有人可以解释一下吗?

这是一个有效的例子:

ui.r

shinyUI(fluidPage(
  sidebarLayout(

    position = "left",

    sidebarPanel(
      selectizeInput("fund", label = NULL, selected = "", choices = c('', LETTERS[1:6]), options = list(placeholder = "Choose something"), width = "350px"),
      verbatimTextOutput("hover")
    ),

    mainPanel(
      plotlyOutput("tsplot")
    )


  )
))

server.r

require(shiny)
require(ggplot2)
require(plotly)

shinyServer(function(input, output) {

  PFobj <- reactive({

    pf <- input$fund
    ts_info <- list(a = "x", b = "y")
    ts_data <- data.frame(Dat = seq(Sys.Date() - 200, Sys.Date(), 1), Val = cumsum(c(100, rnorm(200))))

    list(pf = pf, nav = ts_info, data = ts_data)

  })

  observe({
    if(input$fund != '') {
      output$tsplot <- renderPlotly({
        p <- ggplot(PFobj()$data, aes(x = Dat, y = Val, group = 1, text = paste("</br>Date: ", Dat, "</br>Value: ", Val))) +
          geom_line(colour = "red")
        ggplotly(p, tooltip = c("text"))
      })
    }
  })

  output$hover <- renderPrint({
    d <- event_data("plotly_hover")
    if (!is.null(d)) {cat(d$x, d$y); b <<- d$x}
  })

})

App

1 个答案:

答案 0 :(得分:0)

编辑:经过一番研究,似乎输出是图形位置的指针X轴值。在print(d)输出中尝试hoverd$xd$y为空。

相关问题