0

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
Williams86
  • 320
  • 1
  • 11
  • Please check the updated version of question. – Williams86 Mar 10 '21 at 09:49
  • Thanks. While running the code I get the error `Error in parse: :1:8: unexpected INCOMPLETE_STRING1: paste0('mpg = ..` . Do you also get the same error and that is what you want to correct? – Ronak Shah Mar 10 '21 at 10:20
  • Yes same error coming for me. If you store head(mtcars) in environment and specify selected_row as 1 then this error wouldn't come. But I want to pass reactive values. – Williams86 Mar 10 '21 at 10:24

0 Answers0