title: In R Shiny, how to correctly link matrix values?
body: <p>In the below MWE code, the user has the option to refine model assumptions/inputs through a series of step-wise matrix inputs (3 in this case). The 1st matrix, presented by default when first invoking the App, is a flat rate Y over X periods. The 2nd matrix, invoked by clicking &quot;Show&quot;, allows user to vary Y over periods X (building a &quot;curve&quot;). The 3rd matrix, invoked by clicking &quot;Add scenarios&quot; action button, allows user to add curved scenarios (note that this 3rd matrix doesn't currently expand horizontally for simplicity of MWE).</p>
  <p>Matrices are linked in 1 direction: values in 1st matrix feed into 2nd matrix and 2nd matrix feeds into 3rd, with the last matrix taking precedence in all calculations. (Note that any inputs into an expandable matrix may have to go from right to left, due to a minor bug in shinyMatrix package that I have yet to download the patch for).</p>
  <p>Matrix 1 id in MWE is <code>flatInput</code>, matrix 2 is <code>curveBaseRate</code>, matrix 3 is <code>curveBaseRateAdd</code>.</p>
  <p>Problem I have is if the 2nd matrix is changed (with any added rows), it is not correctly reflected in the 3rd matrix (as shown in the 3rd image at bottom). If the 2nd matrix is not changed but only shown, then the 2nd matrix correctly feeds into the 3rd matrix (as shown in the 2nd image at the bottom). How can this be fixed? I believe there is something wrong with my citation of matrix 2 row/column in my matrix 3 rendered in modal dialog (lines <code>input$curveBaseRate[,1]</code> and <code>input$curveBaseRate[,2]</code>, but I don't know what I'm doing wrong.</p>
  <p>MWE code:</p>
  <pre><code>library(shiny);library(shinyMatrix);library(shinyjs)
  
  f &lt;- function(action,i){as.character(checkboxInput(paste0(action,i),label=NULL))}
  actions       &lt;- c(&quot;show&quot;, &quot;reset&quot;)
  tbl           &lt;- t(outer(actions, c(1,2), FUN = Vectorize(f)))
  colnames(tbl) &lt;- c(&quot;Show&quot;, &quot;Reset&quot;)
  rownames(tbl) &lt;- c(&quot;Base&quot;, &quot;Spread&quot;)
  
  xDflt &lt;- .05 # &lt;&lt; default value for x column of input matrix
  yDflt &lt;- .01  # &lt;&lt; default value for y column of input matrix
  
  flatRate &lt;- function(inputId,x,y){
    matrixInput(inputId, 
                value = matrix(c(x,y), 1, 1, dimnames = list(c(&quot;Base rate&quot;),NULL)),
                rows =  list(extend = FALSE, names = TRUE),
                cols =  list(extend = FALSE, names = FALSE, editableNames = FALSE),
                class = &quot;numeric&quot;)
  } 
  
  curveRate &lt;- function(inputId,w,x,y){
    matrixInput(inputId,
                label = w,
                value = matrix(c(x,y),1,2,dimnames=list(NULL,c(&quot;Period (X)&quot;,&quot;Curved (Y)&quot;))),
                rows =  list(extend = TRUE,  names = FALSE),
                cols =  list(extend = FALSE, names = TRUE, editableNames = FALSE),
                class = &quot;numeric&quot;)
  }  
  
  ui &lt;- 
    fluidPage(
      tags$head( 
        tags$style(HTML(
          &quot;td .checkbox {margin-top: 0; margin-bottom: 0;}
         td .form-group {margin-bottom: 0;}&quot;
        ))
      ),
      titlePanel(&quot;Model&quot;),
      sidebarLayout(
        sidebarPanel(uiOutput(&quot;Panel&quot;)),
        mainPanel(tabsetPanel(tabPanel(&quot;Rates&quot;, value=2),id = &quot;tabselected&quot;))
      ) 
    ) 
  
  server &lt;- function(input,output,session)({
    output$Panel &lt;- renderUI({
        conditionalPanel(
            condition = &quot;input.tabselected == 2&quot;,
            useShinyjs(),
            helpText(&quot;Modeled periods (X):&quot;),
            sliderInput('periods','',min=2,max=120,value=60),
            helpText(&quot;Initial rates (Y):&quot;),
            flatRate(&quot;flatInput&quot;,xDflt,yDflt), 
            helpText(&quot;Generate curves (Y|X):&quot;),
            tableOutput(&quot;checkboxes&quot;),
            hidden(uiOutput(&quot;curveBaseRate&quot;)),
            actionButton(&quot;addScenarios&quot;,&quot;Add scenarios&quot;)
        )
    }) 
    
    ### Begin checkbox matrix ###
    output[[&quot;checkboxes&quot;]] &lt;- 
      renderTable({tbl}, 
                  rownames = TRUE, align = &quot;c&quot;,
                  sanitize.text.function = function(x) x
      )
    
    observeEvent(input[[&quot;show1&quot;]], {
      if(input[[&quot;show1&quot;]]){
        shinyjs::show(&quot;curveBaseRate&quot;)
      } else {
        shinyjs::hide(&quot;curveBaseRate&quot;)
      }
    })
    ### End checkbox matrix ###
    
    output$curveBaseRate &lt;- renderUI({
      req(input$periods,input$flatInput)
      input[[&quot;reset1&quot;]]
      curveRate(&quot;curveBaseRate&quot;,
                &quot;Base rates curve (Y|X):&quot;,
                input$periods,
                input$flatInput[1,1])
    })
    
    outputOptions(output, &quot;curveBaseRate&quot;, suspendWhenHidden = FALSE)
    
    observeEvent(input$addScenarios, {
      showModal(
        modalDialog(
          curveRate(&quot;curveBaseRateAdd&quot;,
                    &quot;Base rates curve (Y|X):&quot;,
                    input$curveBaseRate[,1],
                    input$curveBaseRate[,2]),
          footer =  modalButton(&quot;Close&quot;)
        ))
    }) 
    
  }) 
  
  shinyApp(ui, server)
  </code></pre>
  <p>Explanatory images:</p>
  <ol>
  <li>First image shows 1st user input matrix.</li>
  <li>Second image shows the 2nd user input matrix (after clicking &quot;Show&quot;) rendered and correctly
  feeding into 3rd user input matrix in modal dialog, with no user changes to 2nd input matrix.</li>
  <li>Third image shows incorrect rendering of 3rd input matrix in modal dialog, after user makes changes to 2nd input matrix.</li>
  </ol>
  <p><a href="https://i.stack.imgur.com/Oprxx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Oprxx.png" alt="enter image description here" /></a>
  <a href="https://i.stack.imgur.com/FjWHp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FjWHp.png" alt="enter image description here" /></a>
  <a href="https://i.stack.imgur.com/v79hz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/v79hz.png" alt="enter image description here" /></a></p>