library(shiny)
app <- shinyApp(
ui = fluidPage(
DT::dataTableOutput("mydatatable")
),
server = shinyServer(function(input, output, session) {
mycars <- reactive({ head(mtcars)})
output$mydatatable = DT::renderDataTable(mycars(), selection = 'single',
rownames = FALSE, options = list(dom = 't'))
selected_row <- reactiveVal(value = NULL)
observeEvent(input$mydatatable_rows_selected,{
selected_row(input$mydatatable_rows_selected)
})
observeEvent(selected_row(),
{
showModal(modalDialog(
title = "You have selected a row!",
DiagrammeR::grViz("
digraph flowchart {
graph [layout = dot]
node [shape = rectangle, width = 3, fillcolor = Biege]
a [label = '@@1']
b [label = '@@2']
a -> b
}
[1]: paste0('mpg = ', mycars()$mpg[selected_row()])
[2]: paste0('cyl = ', mycars()$cyl[selected_row()])
", width = 200)
))
})
})
)
app
I am trying to pass mycars() and selected_row() reactive values into DiagrammeR::grViz code but I am getting error.