-
Notifications
You must be signed in to change notification settings - Fork 2
Brush select fix, new elements API #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as off-topic.
This comment was marked as off-topic.
|
Reprex: library(shiny)
library(bslib)
library(g6R)
ui <- page_fillable(
actionButton("add", "Add node"),
g6_output("dag")
)
server <- function(input, output, session) {
output$dag <- render_g6(g6())
observeEvent(
input$add,
{
message("adding node")
g6_add_nodes(
g6_proxy("dag"),
list(
list(
id = "a",
label = "A",
combo = list()
)
)
)
}
)
}
shinyApp(ui, server)Passing |
|
The issue is a missing if (length(el) == 1) {
el <- list(el)
}g6 would expect |
|
@DivadNojnarg just so that we're on the same page. What I meant above is passing list(
list(
id = "a",
label = "A",
combo = list()
)
)does not work, while list(
list(
id = "a",
label = "A",
combo = NULL
)
)does. Which is fine. The issue probably is more the error msg, which is a bit confusing:
What you say above about 1 vs multiple nodes could be a convenience feature, but what you have right now, where you expect a list of nodes (which for 1 node means a |
|
@DivadNojnarg ah, now I understand why I was a bit confused about the right way to pass an empty node combo spec. It is different for g6(
nodes = list(
list(
id = "a",
label = "A",
combo = NULL
)
)
)causes a JS error
So in one case, you have to pass |
|
A full example would be library(shiny)
library(bslib)
library(g6R)
ui <- page_fillable(
actionButton("add", "Add node"),
g6_output("dag")
)
server <- function(input, output, session) {
output$dag <- render_g6(
g6(
nodes = list(
list(
id = "a",
label = "A",
combo = list()
)
)
) |>
g6_behaviors(
drag_canvas(),
zoom_canvas()
)
)
observeEvent(
input$add,
{
message("adding node")
g6_add_nodes(
g6_proxy("dag"),
list(
list(
id = "b",
label = "B",
combo = NULL
)
)
)
}
)
}
shinyApp(ui, server)but here the node addition somehow does not work. Do you see what I'm doing wrong here? |
|
@DivadNojnarg one additional thing to consider: while you can catch much of the "internal ID renaming" in JS <-> R code, whenever 3rd party JS code is involved, e.g. in context menu items, this has to be handled separately. Not a problem, just something to document and be aware of. Code like (value, target, current) => {
Shiny.setInputValue('%s', current.id, {priority: 'event'});
}has to handle its own ID renaming. |
|
@nbenn I'll continue on this PR (renaming it also) as I am gonna change the implementation. Instead of prefixing, I'll maintain a mapping registry of elements (type/id) when they are created and destroyed: graph.on(GraphEvent.AFTER_ELEMENT_CREATE, (e) => {
// add to registry
})
graph.on(GraphEvent.AFTER_ELEMENT_DESTROY, (e) => {
// remove from registry
})Then looking up the registry for an element id, you can find it's type. |
|
@DivadNojnarg yeah, I think this might be the better approach. |
|
@nbenn With the latest commit, you should be ok with BristolMyersSquibb/blockr.dag#33. Regarding the other point above, ie passing combo = NULL (valid) or combo = list() invalid, a quality of live improvement would be to expose higher level helpers for elements like g6_node, g6_edge, g6_combo ... instead of dummy lists. This would allow to perform data consistency checks at the element level based on the g6 API specifications. I would have expected g6 JS to raise an error when something invalid is passed from R but this isn't the case for all properties. Of course, I can't stop supporting basic lists for backward compatibility reasons. |
|
TBD
|
|
TBD (not mandatory):
|
Uh oh!
There was an error while loading. Please reload this page.