Comments (6)
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.
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.
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.
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.
@Ahine this should be fixed now. Please install the latest version from github
from timevis.
Installed the latest version and the fix is reflected on our App. Thanks for addressing it so quickly!
from timevis.
Related Issues (20)
- timezone argument fails in shiny but works in console HOT 1
- Online demo license expired HOT 2
- timeline-arrows package HOT 1
- Deselecting Items does not trigger observeEvent(input$timeline_selected,{}) (RShiny) HOT 1
- Changing language in the viewer HOT 1
- About the language HOT 1
- On which version of visjs-Timeline is Timevis running? HOT 1
- How to format dates in the data retrieved from the widget? HOT 2
- wrong date on timeline HOT 3
- timevis not running in Quarto .qmd HOT 3
- name of the month is an abbreviation in Ukrainian HOT 1
- Crosstalk error: Error: timevis: 'data' must be a data.frame HOT 2
- timevis is excellent HOT 1
- No support for portuguese? HOT 1
- Error using `{crosstalk}` with `timevis()` HOT 1
- Cannot assign HTML attributes to table in content HOT 3
- Handlebars Template stripped out of classes HOT 3
- Stacking performance - update vis.js version? HOT 1
- Show warning or error on duplicate id's HOT 1
- Visualisation Shaking HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from timevis.