【问题标题】:Shiny hover - strange date format闪亮的悬停 - 奇怪的日期格式
【发布时间】:2018-01-15 18:40:03
【问题描述】:

我有一个闪亮的应用程序,其中包含时间序列图和一个悬停事件,它输出当前悬停值的日期和值。奇怪的是,它输出的日期格式我无法完全理解。例如,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}
  })

})

【问题讨论】:

    标签: r date shiny


    【解决方案1】:

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

    【讨论】:

    • verbatimTextOutput("hover") 字段输出是否也正确?
    • 哈哈,对了。我只是立即截图并没有看到输出。是的,它搞砸了。我的坏
    猜你喜欢
    • 2019-04-02
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    • 2013-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多