Skip to content
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

interactive flowchart in Shiny #368

Closed
marton-balazs-kovacs opened this issue Dec 10, 2019 · 5 comments
Closed

interactive flowchart in Shiny #368

marton-balazs-kovacs opened this issue Dec 10, 2019 · 5 comments

Comments

@marton-balazs-kovacs
Copy link

Is it possible to create an interactive flowchart in Shiny where the nodes act like action buttons currently?

@trafficonese
Copy link
Contributor

You might wanna try out the new dev version. #362 was just merged and it adds Shiny capabilities.

You cannot really include actionButtons in the diagramms, as I guess it has some problems with special character escaping, but you can get an actionButton behaviour.

library(DiagrammeR)
library(shiny)

graph <- open_graph(
    system.file("extdata/example_graphs_dgr/repository.dgr",
      package = "DiagrammeR"))

ui <- fluidPage(
  grVizOutput("dg")
  , verbatimTextOutput("print")
)

server <- function(input, output, session) {
  output$dg <- renderGrViz({
    render_graph(graph, layout = "kk")
  })
  txt <- reactive({
    req(input$dg_click)
    nodeval <- input$dg_click$nodeValues[[1]]
    return(paste(nodeval, " is clicked"))
  })
  output$print <- renderPrint({
    req(txt())
    txt()
  })
}

shinyApp(ui, server)


@marton-balazs-kovacs
Copy link
Author

This is great! I just want to use it as a map for the app that can be used to easily navigate.

@marton-balazs-kovacs
Copy link
Author

@trafficonese Can I use this somehow with a graph created with the grViz function?

@trafficonese
Copy link
Contributor

@marton-balazs-kovacs Yes it is possible.

library(DiagrammeR)
library(shiny)

ui <- fluidPage(
  grVizOutput("dg"),
  verbatimTextOutput("print")
)

server <- function(input, output, session) {
  output$dg <- renderGrViz({
    grViz("
digraph a_nice_graph {

# node definitions with substituted label text
node [fontname = Helvetica]
a [label = '@@1']
b [label = '@@2-1']
c [label = '@@2-2']
d [label = '@@2-3']
e [label = '@@2-4']
f [label = '@@2-5']
g [label = '@@2-6']
h [label = '@@2-7']
i [label = '@@2-8']
j [label = '@@2-9']

# edge definitions with the node IDs
a -> {b c d e f g h i j}
}

[1]: 'top'
[2]: 10:20
")
  })
  txt <- reactive({
    req(input$dg_click)
    nodeval <- input$dg_click$nodeValues[[1]]
    return(paste(nodeval, " is clicked"))
  })
  output$print <- renderPrint({
    txt()
  })
}

shinyApp(ui, server)

@marton-balazs-kovacs
Copy link
Author

Wow, thanks. I was looking for this everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants