0

I have two issues that may or may not be related. Here is code that demonstrates both problems UI.r

library(shiny)
library(shinyBS)
shinyUI(fluidPage(
  titlePanel("Basic example"),

  fluidRow(
  mainPanel(
   # ggvisOutput("fiveMinPlot"),
    uiOutput("plotUI"))

)))

server.r

library(shiny)
library(shinyBS)

tooltipMaker <- function(x){
  if(is.null(x)) return(NULL)
  row <- testData[testData$rowID == x$rowID,]
  paste0(c('TradeID','time','PL'), ": ", format(row[,c('TradeID','time','PL')]), collapse = "<br />")
}
testData <- data.frame(cbind(time = rep(-4:10 * 500,3),
                             TradeID=c(rep("this",15),rep("that",15),rep("the other",15)),
                             PL=c(1:15,4:18,7:21),
                             theColor=c(rep("green",15),rep("lightblue",15),rep("red",15)),
                             theWidth=c(rep(1,30),rep(2,15)),
                             rowID=1:45))
as.numericDF <- function(dataframe) 
{
  if(class(dataframe)!="data.frame") dataframe <- data.frame(dataframe)
  for(i in 1:length(dataframe)){
    suppressWarnings({
      if(!any(is.na(as.numeric(levels(dataframe[[i]])))))
        dataframe[[i]] <- as.numeric(levels(dataframe[[i]])[as.numeric(dataframe[[i]])])
    })
  }
  return(dataframe)
}

shinyServer(function(input, output) {
  observe({
    testData <- as.numericDF(testData)
    ggvis(testData,x=~time,y=~PL, stroke := ~theColor,strokeWidth:=~theWidth,key := ~rowID) %>% layer_lines()%>%
      add_tooltip(tooltipMaker,"hover") %>%
      bind_shiny("theGraph")
  })
  output$plotUI <- renderUI({ #this best represents my actual code
    return(ggvisOutput("theGraph"))
  })
})

Issue #1

Run it while watching it carefully, all 3 lines render, then 2 immediately disappear. In this case the red one appears to always remain, but in my sample set its one at random.

I opened the generated HTML with chrome's built-in inspector and noticed that it looks like all 3 lines were replaced with the first line.

http://imagizer.imageshack.us/a/img661/831/sRgYMY.jpg

I then hit refresh a bunch of times. To my surprise, it works properly about 20% of the time. Here's what it looks like when it works

http://imagizer.imageshack.us/a/img540/3053/0CrwFP.jpg

How does it work sometimes?! I thought computers were deterministic...

Issue #2

Hover over a line.

You'll notice that the hover data always displays the data that represents the farthest-left data point. Why?

hedgedandlevered
  • 2,314
  • 2
  • 25
  • 54

0 Answers0