title: R shiny, how to make Color differnce in values when comparing dataframes emp.data A and emp.data B
body: <p>I made a Shiny App that compares the values of two data frames emp.data_A and emp.data_B.  and gives the color. It currently works when the rows and columns on both data frames are the same lengths, but it does not function when the data frames have different lengths. Is anyone able to assist me?</p>
  <ol>
  <li>It should function even if the lengths of the data frames are different.</li>
  <li>I just need the color difference on the columns &quot;emp name&quot; and &quot;salary&quot; when both are selected in options.</li>
  <li>In emp.data_A, I've created a column called &quot;credit&quot; to account for the different lengths.</li>
  </ol>
  <p>below is my code:</p>
  <pre><code>library(shiny)
  library(gt)
  
  emp.data_A &lt;- data.frame(
    emp_id = c(1:5),
    emp_name = c(&quot;Rick&quot;,&quot;Dan&quot;,&quot;Michelle&quot;,&quot;Ryan&quot;,&quot;Gary&quot;),
    salary = c(623.3,515.2,611.0,735.0,844.25),
    credit = c(1,2,3,4,5))
  
  emp.data_A
  
  
  emp.data_B &lt;- data.frame(
    emp_id = c(1:5),
    emp_name = c(&quot;Rick&quot;,&quot;Dan&quot;,&quot;Michelle&quot;,&quot;Ryan&quot;,&quot;Gary&quot;),
    salary = c(623.3,515.2,611.0,729.0,843.25))
  emp.data_B
  
  shinyApp(
    ui = fluidPage(
      fluidRow(
        selectInput(&quot;dataset5&quot;, 
                    &quot;Choose a dataset:&quot;,
                    choices = c(&quot;SelectDataSet&quot;, &quot;both&quot;, &quot;emp.data_A&quot;, &quot;emp.data_B&quot;)),
        downloadButton(&quot;downloadData5&quot;, &quot;Download&quot;)
      ),
      hr(),
      fluidRow(
        column(width = 6, gt_output(&quot;table1&quot;)),
        column(width = 6, gt_output(&quot;table2&quot;))
      )
    ),
    server = function(input, output,session) {
      datasetInput1 &lt;- reactive({
        if (input$dataset5 == &quot;both&quot; || input$dataset5 == &quot;emp.data_A&quot;) {
          emp.data_A 
        } else if (input$dataset5 == &quot;emp.data_B&quot;) {
          emp.data_B 
        }
      })
      datasetInput2 &lt;- reactive({
        if (input$dataset5 == &quot;both&quot;) {
          tbl_diffs &lt;- which(emp.data_A != emp.data_B, arr.ind = TRUE)
          tbl_gt_B &lt;- emp.data_B %&gt;% 
            gt()
          for (i in seq_len(nrow(tbl_diffs))) {
            tbl_gt_B &lt;- tbl_gt_B %&gt;%
              tab_style(
                style = list(
                  cell_fill(color = &quot;#FFFF00&quot;)
                ),
                locations = cells_body(
                  columns = tbl_diffs[[i, &quot;col&quot;]],
                  rows = tbl_diffs[[i, &quot;row&quot;]]
                )
              )
          }
          tbl_gt_B
        }
      })
      output$table1 &lt;- render_gt(
        datasetInput1() 
      )
      output$table2 &lt;- render_gt(
        datasetInput2()
      )
    }
  )
  
  </code></pre>