cyjShiny
cyjShiny copied to clipboard
[Bug] setNodePositions doesn't work properly when id contains apostrophe
Hello, when node ID contains an apostrophe, setNodePositions cannot set all posistion correctly. Please see the example (with Shiny) below. If the ID of B'3
is replaced by B3
, it can work correctly again. By the way, B\\'3
also works.
library(cyjShiny)
df_pos <- data.frame(id=c("A", "B'3", "C"),
x=c(0, 100, 200),
y=c(200, 100, 0),
stringsAsFactors = FALSE)
df_edges <- data.frame(source=c("A", "B'3"),
target=c("C", "A"),
interaction=c("inter", "inter"),
stringsAsFactors = FALSE)
server <- shinyServer(function(input, output, session) {
output$cyj_result <- cyjShiny::renderCyjShiny({
my_network_json <- cyjShiny::dataFramesToJSON(df_edges)
res_cyjshiny <- cyjShiny(graph = my_network_json,
layoutName = "preset", # not implemented, so all at 0, 0
height = "750")
return(res_cyjshiny)
})
# button
observeEvent(input$button_preset_layout, ignoreInit=TRUE, {
setNodePositions(session, df_pos)
fit(session, 50)
})
})
ui <- shinyUI(fluidPage(
actionButton("button_preset_layout", "Preset"),
cyjShiny::cyjShinyOutput("cyj_result", width = "100%", height = "750")
))
runApp(shinyApp(ui=ui,server=server))
@Jinchao-Yu Your useful request - to support x,y positions in the data.frame method - provides a good opportunity to refactor the graphsToJSON functions. I created a new branch to support that. I will keep you posted on my progress.