I am trying to pass two reactive values into my Diagrammer::grViz code like
[1]: paste0("Count is : \n", df()$count[rownum()])
where df() is my dataframe and rownum() is a specific selected row number.
I am getting error like 'df() not found' or 'rownum() not found'. I suppose that this error is coming because the whole grViz code inside the inverted commas.
Also \n
is not working inside paste0()
.
Is there any solution to this?
Thanks in advance.
Example code below :
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 = \n', mycars()$mpg[selected_row()])
[2]: paste0('cyl = \n', mycars()$cyl[selected_row()])
", width = 200)
))
})
})
)
app