Giter Site home page Giter Site logo

Comments (6)

daattali avatar daattali commented on May 26, 2024

Thanks for reporting. That sounds strange, not sure if it's because of the JavaScript library or the conversion to R. Can you please attach a minimal reproducible example?

from timevis.

Ahine avatar Ahine commented on May 26, 2024

Sure, this example demonstrates it well:

The page will show two timelines, one made with 4 elements, the other with 11. When you select an element in the first timeline, the console prints the Ids without extra white space, "4", "2" etc.

When you select an element in the second timeline, the console prints single-digit Ids with an extra leading space ex. " 4", " 2"

`library(shiny)
library(timevis)

data1 <- data.frame(
id = 1:4,
content = c("Item one", "Item two",
"Ranged item", "Item four"),
start = c("2016-01-10", "2016-01-11",
"2016-01-20", "2016-02-14 15:00:00"),
end = c(NA, NA, "2016-02-04", NA)
)

data2 <- data.frame(
id = 1:11,
content = c("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven"),
start = c("2016-01-10", "2016-01-11",
"2016-01-20", "2016-02-14 15:00:00", "2016-03-05", "2016-04-23", "2017-01-03", "2017-08-23", "2016-12-23", "2017-11-23", "2017-08-12"),
end = c(NA, NA, "2016-02-04", NA, NA,NA,NA,NA,NA,NA,NA)
)

ui <- fluidPage(h1("Timeline 1 (fewer than 10 elements)"),
timevisOutput("timeline1"),
h1("Timeline 2 (more than 10 elements)"),
timevisOutput("timeline2"))

server <- function(input, output){

output$timeline1 <- renderTimevis({timevis(data1)})
output$timeline2 <- renderTimevis({timevis(data2)})

idString <- NA
observeEvent(input$timeline1_selected, {
idString <- input$timeline1_selected
print(idString)
})

observeEvent(input$timeline2_selected, {
idString <- input$timeline2_selected
print(idString)
})

}

shinyApp(ui, server)`

from timevis.

daattali avatar daattali commented on May 26, 2024

Thank you! I'll try to take a look. Have you seen if the same thing happens if you go up to 100 and then there'll be 2 spaces?

from timevis.

daattali avatar daattali commented on May 26, 2024

I found the culprit.

Before passing the dataframe to javascript, I transform it into a format that's compatible with the javascript library (the dataframe is converted into a list of rows, where each row is a list of columns). In this process, I use this code:

apply(df, 1, function(row) as.list(row[!is.na(row)]))

After looking at the help file of apply(), it looks like it converts the given dataframe into a matrix.

For some reason, when converting to a matrix, it tries to make this numeric column a consistent width. I'm not quite sure yet why it does this, but it's definitely this line that causes what you're seeing.

Proof:

> df <- data.frame(a = c(5,100), b = c("a","b"))
> as.matrix(df)
     a     b  
[1,] "  5" "a"
[2,] "100" "b"

The fix is to either do the matrix conversion without this padding, or to not use the apply() function. I'll have to see what to do

from timevis.

daattali avatar daattali commented on May 26, 2024

@Ahine this should be fixed now. Please install the latest version from github

from timevis.

Ahine avatar Ahine commented on May 26, 2024

Installed the latest version and the fix is reflected on our App. Thanks for addressing it so quickly!

from timevis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.