Create a Shiny app to filter rows and columns simultaneously from a genetic distance matrix

Hi,
I am a new Shiny user and I would like to create an app that allows a user to simultaneously filter rows and columns from a distance matrix. I guess the widget selectInput would alow me to make choices to select from the matrix below

|                                  | CruSim2 | CruSim1 | BatKem3 | BatKem2 | ValMicro2 | BatKem1 | BatSten1_a | BatSten1_b | VallMicro1 | MagHoe1 | Amag_GK30097_PI468340_UGA_B | Ahoeh_VP9094_PI688954_Embrapa_B |
|----------------------------------|---------|---------|---------|---------|-----------|---------|------------|------------|------------|---------|-----------------------------|---------------------------------|
| CruSim2                          |         | 67.41   | 60.68   | 61.33   | 60.12     | 60.58   | 61.04      | 59.68      | 56.52      | 56.90   | 49.66                       | 51.03                           |
| CruSim1                          | 67.41   |         | 60.41   | 61.14   | 60.14     | 60.38   | 60.95      | 59.66      | 55.84      | 56.28   | 49.64                       | 51.10                           |
| BatKem3                          | 60.68   | 60.41   |         | 61.19   | 60.56     | 61.53   | 61.80      | 61.92      | 54.96      | 55.24   | 49.07                       | 50.95                           |
| BatKem2                          | 61.33   | 61.14   | 61.19   |         | 65.15     | 65.56   | 62.16      | 60.46      | 55.02      | 55.53   | 48.57                       | 50.49                           |
| ValMicro2                        | 60.12   | 60.14   | 60.56   | 65.15   |           | 67.64   | 61.81      | 59.89      | 54.93      | 54.85   | 48.50                       | 50.42                           |
| BatKem1                          | 60.58   | 60.38   | 61.53   | 65.56   | 67.64     |         | 62.19      | 60.80      | 54.63      | 54.93   | 48.62                       | 50.60                           |
| BatSten1_a                       | 61.04   | 60.95   | 61.80   | 62.16   | 61.81     | 62.19   |            | 65.63      | 54.90      | 55.22   | 48.38                       | 50.05                           |
| BatSten1_b                       | 59.68   | 59.66   | 61.92   | 60.46   | 59.89     | 60.80   | 65.63      |            | 54.22      | 54.34   | 48.42                       | 50.40                           |
| VallMicro1                       | 56.52   | 55.84   | 54.96   | 55.02   | 54.93     | 54.63   | 54.90      | 54.22      |            | 69.09   | 53.80                       | 48.30                           |
| MagHoe1                          | 56.90   | 56.28   | 55.24   | 55.53   | 54.85     | 54.93   | 55.22      | 54.34      | 69.09      |         | 53.86                       | 48.25                           |
| Amag_GK30097_PI468340_UGA_B      | 49.66   | 49.64   | 49.07   | 48.57   | 48.50     | 48.62   | 48.38      | 48.42      | 53.80      | 53.86   |                             | 55.47                           |
| Ahoeh_VP9094_PI688954_Embrapa_B  | 51.03   | 51.10   | 50.95   | 50.49   | 50.42     | 50.60   | 50.05      | 50.40      | 48.30      | 48.25   | 55.47                       |                                 |
| Amag_GK30097_PI468340_Embrapa2_B | 50.09   | 50.08   | 49.42   | 48.87   | 49.04     | 49.01   | 48.69      | 48.51      | 54.25      | 54.30   | 71.20                       | 54.83                           |
| Avali_VP13514_Embrapa_B          | 49.08   | 49.04   | 48.77   | 48.31   | 48.17     | 48.21   | 48.08      | 47.98      | 56.16      | 56.05   | 65.80                       | 55.49                           |
| Amag_VS13751_Embrapa_B           | 50.09   | 49.94   | 49.47   | 49.11   | 48.94     | 49.05   | 48.82      | 48.70      | 54.32      | 54.47   | 67.96                       | 55.65                           |
| Akemp_V14673_Embrapa_A           | 52.73   | 52.65   | 51.79   | 52.01   | 52.06     | 52.02   | 51.86      | 52.26      | 49.75      | 49.59   | 53.41                       | 61.04                           |
| Ahoeh_V14547_Embrapa_B           | 52.20   | 52.22   | 51.97   | 51.57   | 51.51     | 51.49   | 51.24      | 51.38      | 49.42      | 49.45   | 56.35                       | 70.58                           |
| Ahoeh_VP9140_PI666086_Embrapa_B  | 51.91   | 52.07   | 51.89   | 51.42   | 51.26     | 51.31   | 50.84      | 51.04      | 49.11      | 49.29   | 56.27                       | 70.34                           |
| Amag_Se3777_IBONE_B              | 50.01   | 50.01   | 49.38   | 49.04   | 48.99     | 49.08   | 48.66      | 48.71      | 54.48      | 54.53   | 68.94                       | 55.84                           |
| Avali_GK30011_PI468154_UGA_B     | 49.35   | 49.39   | 49.17   | 48.75   | 48.56     | 48.73   | 48.44      | 48.34      | 56.73      | 56.76   | 66.58                       | 55.76                           |
| Ahoeh_VM13985_Embrapa_B          | 51.80   | 51.84   | 51.70   | 51.19   | 51.20     | 51.24   | 50.88      | 50.84      | 49.22      | 49.27   | 56.03                       | 70.89                           |
| Amag_VS13761_Embrapa_B           | 50.25   | 50.23   | 49.59   | 49.22   | 49.01     | 49.18   | 48.96      | 48.74      | 54.51      | 54.64   | 68.49                       | 55.65                           |
| Akemp_V14886_Embrapa_A           | 54.19   | 54.05   | 53.04   | 53.62   | 53.41     | 53.32   | 53.52      | 53.46      | 50.82      | 50.91   | 53.55                       | 61.67                           |

Any help would be very appreciated,

Francisco

Hi @FrandeBlas, welcome to shiny! You are correct that selectInput() would allow you to make choices from the data you shared. In the example app below, which uses a small subset of your data, two inputs are created. One from the values in the first column of the data frame and one from the column names (first column name removed).

Since I wasn't quite sure on the output you're expecting, I set up two different tables. The first filters the table down to show only the intersection of the inputs selected. The second shows the full table at all times, highlighting the intersection of selections (this table uses the kableExtra package). I hope this helps.

library(shiny)
library(tidyverse)
library(kableExtra)

# distance data
df = data.frame(
  . = c('CruSim2', 'CruSim1', 'BatKem3', 'BatKem2'),
  CruSim2 = c(NA, 67.41, 60.68, 61.33),
  CruSim1 = c(67.41, NA, 60.41, 61.14),
  BatKem3 = c(60.68, 60.41, NA, 61.19),
  BatKem2 = c(61.33, 61.14, 61.19, NA)
)

ui <- fluidPage(
  br(),
  fluidRow(
    # column for inputs
    column(2,
           selectInput('from', 
                       'From', 
                       choices = df$., 
                       multiple = F, 
                       width = '200px'),
           selectInput('to', 
                       'To', 
                       choices = names(df)[names(df) != '.'], 
                       multiple = F, 
                       width = '200px')
           ),
    # column for tables
    column(10,
           HTML('Filtered table output'),
           br(),
           tableOutput('table_filtered'),
           br(),
           br(),
           HTML('Highlighted table output'),
           br(),
           tableOutput('table_highlighted')
           )
    )
)

server <- function(input, output, session) {
  
  # filtered table
  output$table_filtered = renderTable({
    req(input$from, input$to)
    
    col = which(names(df) == input$to)
    
    df %>%
      filter(. == input$from) %>%
      select_at(c(1, col))
  })
  
  # highlighted table
  output$table_highlighted = function() {
    req(input$from, input$to)
    
    myrow = which(df$. == input$from)
    col = which(names(df) == input$to)
    
    df[myrow,col] = paste0('<font style="background-color: yellow;">', df[myrow,col], '</font>')
    
    kbl(df, 'html', escape = F, align = 'c') %>%
      kable_paper(full_width = F, position = 'left')  %>%
      column_spec(1:length(df), width = '5em')
  }
  
}

shinyApp(ui, server)

2 Likes

Dear @scottyd22 , I really appreciate the time you dedicated to writing this code down, this is great!
Your example works perfectly, and both outputs are a good option. I tried using my whole data.frame and I don't get any output. I'll keep trying to check on the code to see if there is something I'm missing.
Thank you!

If you can share the output of dput(yourdataframe), I'm happy to help troubleshoot.

Sure! thank you for this. The app is working! just very slowly. This is the output (shortened as it is too big to paste here) :

  62.42, 62.42, 62.52, 62.69, 62.48, 62.75, 65.23, 65.26, 65.56, 
    65.5, 65.24, 65.65, 65.42, 73.57, 73.86, 72.01, 72.27, 73.26, 
    73.35, 73.63, 73.87, 74.03, 73.17, 74.01, 73.87, 73.8, 74.26, 
    73.54, 73.74, 76.07, 73.44, 75.58, 75.67, 75.01, 76.26, 75.64, 
    75.61, 73.34, 75.52, 76.15, 76.18, 76, 75.62, 83.45, 100, 
    81.2, 77.62, 77.47, 78.33, 78.35, 78.59, 77.78, 78.61, 79.1, 
    79.97, 79.67, 80.07, 79.23, 79.75, 80.19, 79.51, 80.01, 79.79, 
    80.12, 80.09, 80.02, 79.91, 80.03, 74.36, 74.56, 76.48, 76.6, 
    76.69, 76.95, 77.16, 52.57, 51.71, 43.09), Asten_13824_PI599186_GRIN.USDA_A = c(55.65, 
    55.87, 54.84, 55.16, 54.9, 54.69, 58.02, 57.56, 52.16, 52.38, 
    54.35, 63.04, 54.33, 54.82, 54.78, 69.44, 64.66, 64.82, 54.92, 
    55.12, 64.8, 54.97, 71.4, 71.25, 67.72, 71.17, 69.26, 68.54, 
    55.28, 70.97, 61.89, 61.48, 61.4, 61.36, 62.16, 62.09, 62.21, 
    60.61, 59.12, 60.19, 60.11, 60.63, 60.57, 60.57, 58.53, 58.9, 
    58.35, 60.41, 60.16, 60.3, 59.92, 59.81, 59.88, 59.82, 59.78, 
    59.77, 59.71, 59.5, 59.68, 60.06, 60.05, 60.63, 60.53, 60.48, 
    60.73, 60.32, 60.61, 67.39, 71.4, 55.29, 71.15, 57.49, 57.05, 
    57.08, 57, 57.02, 57.51, 57.5, 57.91, 57.73, 56.27, 57.12, 
    56.16, 56.64, 56.91, 57.3, 56.85, 57.09, 70.53, 67.88, 69.39, 
    71, 70.79, 71.26, 71.22, 70.86, 71.73, 70.23, 71.36, 70.1, 
    72.94, 71.98, 70.6, 71.71, 59.82, 59.46, 59.04, 72.24, 72.02, 
    71.42, 75.43, 71.85, 70.95, 74.55, 71.91, 75.18, 75.27, 77.04, 
    76.82, 74.98, 76.09, 77.15, 75.61, 75.94, 75.57, 76.06, 76.1, 
    76.25, 77.02, 76.97, 69.05, 69.87, 73.46, 68.5, 67.9, 68.17, 
    67.72, 68.07, 67.82, 73.36, 73.96, 74.73, 72.2, 74.37, 73.47, 
    59.51, 73.46, 76.06, 71.12, 72.22, 73.13, 64.52, 65.35, 65.26, 
    64.6, 64.97, 64.35, 63.99, 64.56, 64.22, 61.49, 62.77, 63.13, 
    63.26, 63.54, 63.33, 63.32, 63.4, 62.82, 62.86, 61.32, 62.04, 
    62.3, 62.22, 62.49, 62.3, 62.75, 62.6, 62.9, 62.89, 62.64, 
    62.81, 62.61, 62.6, 63.75, 64.33, 63.46, 63.12, 63.71, 63.34, 
    62.92, 62.82, 62.86, 63.03, 62.98, 63.15, 65.62, 65.82, 66.09, 
    66.11, 65.57, 65.9, 65.84, 74.2, 74.55, 72.58, 72.96, 73.87, 
    73.92, 74.4, 74.43, 74.65, 73.56, 74.56, 74.49, 74.2, 74.71, 
    74.27, 74.42, 76.67, 74.05, 76.03, 76.32, 75.78, 76.68, 76.34, 
    76.24, 74.12, 76.25, 76.82, 76.9, 76.71, 76.24, 80.88, 81.2, 
    100, 78.84, 78.65, 79.55, 79.42, 79.54, 78.74, 79.73, 80.31, 
    81.13, 80.85, 81.29, 80.16, 80.81, 81.34, 80.55, 81.16, 80.92, 
    81.21, 81.14, 81.19, 81.12, 81.14, 75.1, 75.34, 77.04, 77.2, 
    77.35, 77.19, 77.61, 52.75, 52.06, 42.99), MagKuhl1 = c(58.26, 
    57.9, 56, 56.16, 55.24, 55.61, 55.78, 55.14, 60.84, 61.38, 
    55.59, 47.9, 56.4, 53.57, 56.23, 49.75, 49.11, 48.8, 56.46, 
    54.19, 48.79, 57.16, 51.2, 51.45, 50.33, 53.07, 52, 50.66, 
    58.12, 50.35, 50.38, 51.65, 51.49, 51.74, 50.59, 50.84, 50.72, 
    49.87, 50.5, 50.5, 50, 49.48, 49.6, 49.62, 50.01, 49.82, 
    49.79, 49.42, 48.65, 48.77, 48.97, 49.18, 48.87, 49.53, 49.62, 
    49.72, 49.63, 48.9, 49.25, 49.06, 49.01, 49.14, 48.98, 49.01, 
    49.25, 48.71, 48.91, 53.07, 52.65, 56.66, 51.59, 55.51, 56.3, 
    56.77, 56.9, 56.62, 55.89, 56, 56.12, 55.67, 58.13, 57.34, 
    62.15, 60.81, 58.98, 57.94, 58.13, 58.14, 51.28, 51.91, 52.49, 
    51.07, 52.98, 50.51, 50.82, 52.52, 50.49, 53.7, 53.73, 53, 
    51.78, 51.58, 53.42, 51.95, 45.28, 44.79, 45.08, 51.06, 51.76, 
    51.86, 49.94, 51.26, 51.69, 49.72, 51.48, 50.17, 50.37, 51.05, 
    51.13, 49.99, 50.21, 51.19, 50.18, 50.72, 50.56, 50.45, 50.58, 
    50.64, 50.96, 50.86, 52.58, 51.3, 51.97, 50.88, 51.38, 50.04, 
    50.9, 50.33, 50.72, 52.32, 52.88, 52.34, 54.2, 53.62, 54.05, 
    45.01, 51.36, 52.8, 54.19, 54.83, 53.76, 47.61, 47.72, 48.31, 
    47.21, 47.57, 47.27, 47.76, 47.46, 48.19, 46.75, 47.38, 46.81, 
    47.08, 47.22, 47.01, 46.81, 46.81, 46.15, 46.49, 45.86, 45.6, 
    45.9, 46.1, 46.57, 45.81, 46.1, 45.99, 46.09, 46.42, 46.23, 
    46.3, 46.44, 46.38, 47.48, 47.27, 46.47, 46.58, 47.09, 46.42, 
    47.12, 46.3, 46.15, 45.98, 46.69, 46.86, 47.92, 48.47, 48.15, 
    48.57, 48.42, 48.42, 48.27, 51.9, 53.08, 58.95, 59.11, 53.91, 
    53.08, 54.14, 52.95, 53.18, 54.3, 52.72, 53.04, 53.31, 53.33, 
    55.07, 55.05, 52.69, 53.22, 53.66, 52.9, 52.75, 53.15, 52.83, 
    52.56, 53.42, 53.8, 53.06, 53.69, 53.36, 53.24, 51.99, 51.71, 
    52.06, 52.89, 52.44, 52.24, 51.78, 51.73, 52.13, 52.38, 51.71, 
    52.4, 51.9, 52.12, 51.55, 52.05, 52.15, 51.91, 52.25, 52.21, 
    52.05, 52.16, 52.42, 52.29, 52.24, 52.99, 53.12, 52.26, 52.27, 
    52.66, 52.9, 52.7, 52.84, 100, 58.55), IpaDur4 = c(51.41, 
    50.93, 50.69, 50.39, 49.84, 50.17, 49.27, 48.36, 55.73, 56.43, 
    48.16, 41.32, 50.46, 47.08, 49.46, 41.23, 42.21, 42.23, 49.44, 
    47.69, 42.15, 49.51, 42.28, 42.47, 44.08, 43.37, 42.87, 44.27, 
    50.88, 42.6, 43.38, 44.59, 44.57, 44.99, 43.8, 44.08, 44.01, 
    42.61, 43.35, 43.54, 43.14, 42.52, 42.65, 42.74, 43.95, 43.79, 
    42.86, 42.66, 41.67, 41.84, 42.14, 42.29, 42.03, 42.7, 42.87, 
    42.97, 42.74, 42.1, 42.33, 42.22, 42.07, 42.16, 41.91, 42.22, 
    42.46, 41.92, 41.93, 49.28, 45.99, 49.24, 42.62, 48.64, 49.48, 
    49.91, 50.09, 49.81, 49.06, 49.16, 49.2, 48.69, 50.62, 50.38, 
    51.52, 50.27, 51.73, 50.46, 50.81, 50.78, 42.42, 48.46, 43.43, 
    42.53, 43.26, 42.58, 42.62, 45.5, 42.28, 44.08, 43.84, 43.24, 
    44.46, 42.49, 43.49, 43.51, 52.77, 52.97, 53.35, 42.69, 42.71, 
    43.14, 41.5, 43.44, 43.9, 41.26, 43.47, 41.2, 41.34, 42.01, 
    42.56, 41.15, 41.32, 42.22, 41.26, 41.66, 41.59, 41.42, 41.59, 
    41.47, 41.8, 41.84, 47.23, 47.64, 44.76, 43.88, 44.51, 43.2, 
    44.14, 43.49, 43.97, 45.28, 45.34, 45.28, 45.41, 45.01, 45.64, 
    53.04, 43.33, 44.86, 44.82, 45.36, 46.3, 50.79, 49.89, 50.72, 
    52.24, 52.64, 52.56, 53.18, 53.4, 54.39, 55.55, 55.27, 54.8, 
    54.97, 55.17, 55.01, 55.44, 55.5, 54.72, 55.08, 57.67, 57.34, 
    57.42, 57.24, 57.34, 57.44, 56.93, 56.81, 56.97, 57.14, 57.86, 
    57.96, 58.25, 58.25, 54.17, 53.85, 54.03, 54.22, 54.56, 54.21, 
    55.02, 54.67, 54.61, 54.35, 54.99, 55.05, 50.53, 50.87, 50.64, 
    50.65, 50.43, 50.37, 50.21, 43.61, 45.18, 44.54, 44.7, 44.35, 
    44.62, 44.42, 44.73, 44.71, 44.8, 45.13, 44.88, 45.19, 44.88, 
    44.74, 44.68, 44.55, 44.96, 44.4, 44.76, 44.75, 44.57, 44.65, 
    44.5, 45.29, 44.72, 43.91, 44.41, 44.4, 44.09, 43.12, 43.09, 
    42.99, 43.5, 43.1, 43.53, 42.54, 42.5, 43.76, 43.47, 42.57, 
    43.11, 42.67, 42.87, 42.42, 42.85, 42.9, 42.75, 42.98, 43.06, 
    42.82, 42.92, 43.08, 43.02, 42.98, 44.7, 44.72, 44.05, 44.12, 
    44.25, 44.63, 44.39, 58.43, 58.55, 100)), class = "data.frame", row.names = c(NA, 
-268L))

Thanks for sharing @FrandeBlas. Unfortunately, the truncated version does not create a data frame. Could you try the following (smaller sample, but may still help with troubleshooting)? I chose 20 rows and 20 columns, but whatever you can fully paste in would be helpful.

dput(yourdataframe[1:20, 1:20]

Here it is:

structure(list(Sample = c("CruSim2", "CruSim1", "BatKem3", "BatKem2", 
"ValMicro2", "BatKem1", "BatSten1_a", "BatSten1_b", "VallMicro1", 
"MagHoe1", "Amag_GK30097_PI468340_UGA_B", "Ahoeh_VP9094_PI688954_Embrapa_B", 
"Amag_GK30097_PI468340_Embrapa2_B", "Avali_VP13514_Embrapa_B", 
"Amag_VS13751_Embrapa_B", "Akemp_V14673_Embrapa_A", "Ahoeh_V14547_Embrapa_B", 
"Ahoeh_VP9140_PI666086_Embrapa_B", "Amag_Se3777_IBONE_B", "Avali_GK30011_PI468154_UGA_B"
), CruSim2 = c(NA, 67.41, 60.68, 61.33, 60.12, 60.58, 61.04, 
59.68, 56.52, 56.9, 49.66, 51.03, 50.09, 49.08, 50.09, 52.73, 
52.2, 51.91, 50.01, 49.35), CruSim1 = c(67.41, NA, 60.41, 61.14, 
60.14, 60.38, 60.95, 59.66, 55.84, 56.28, 49.64, 51.1, 50.08, 
49.04, 49.94, 52.65, 52.22, 52.07, 50.01, 49.39), BatKem3 = c(60.68, 
60.41, NA, 61.19, 60.56, 61.53, 61.8, 61.92, 54.96, 55.24, 49.07, 
50.95, 49.42, 48.77, 49.47, 51.79, 51.97, 51.89, 49.38, 49.17
), BatKem2 = c(61.33, 61.14, 61.19, NA, 65.15, 65.56, 62.16, 
60.46, 55.02, 55.53, 48.57, 50.49, 48.87, 48.31, 49.11, 52.01, 
51.57, 51.42, 49.04, 48.75), ValMicro2 = c(60.12, 60.14, 60.56, 
65.15, NA, 67.64, 61.81, 59.89, 54.93, 54.85, 48.5, 50.42, 49.04, 
48.17, 48.94, 52.06, 51.51, 51.26, 48.99, 48.56), BatKem1 = c(60.58, 
60.38, 61.53, 65.56, 67.64, NA, 62.19, 60.8, 54.63, 54.93, 48.62, 
50.6, 49.01, 48.21, 49.05, 52.02, 51.49, 51.31, 49.08, 48.73), 
    BatSten1_a = c(61.04, 60.95, 61.8, 62.16, 61.81, 62.19, NA, 
    65.63, 54.9, 55.22, 48.38, 50.05, 48.69, 48.08, 48.82, 51.86, 
    51.24, 50.84, 48.66, 48.44), BatSten1_b = c(59.68, 59.66, 
    61.92, 60.46, 59.89, 60.8, 65.63, NA, 54.22, 54.34, 48.42, 
    50.4, 48.51, 47.98, 48.7, 52.26, 51.38, 51.04, 48.71, 48.34
    ), VallMicro1 = c(56.52, 55.84, 54.96, 55.02, 54.93, 54.63, 
    54.9, 54.22, NA, 69.09, 53.8, 48.3, 54.25, 56.16, 54.32, 
    49.75, 49.42, 49.11, 54.48, 56.73), MagHoe1 = c(56.9, 56.28, 
    55.24, 55.53, 54.85, 54.93, 55.22, 54.34, 69.09, NA, 53.86, 
    48.25, 54.3, 56.05, 54.47, 49.59, 49.45, 49.29, 54.53, 56.76
    ), Amag_GK30097_PI468340_UGA_B = c(49.66, 49.64, 49.07, 48.57, 
    48.5, 48.62, 48.38, 48.42, 53.8, 53.86, NA, 55.47, 71.2, 
    65.8, 67.96, 53.41, 56.35, 56.27, 68.94, 66.58), Ahoeh_VP9094_PI688954_Embrapa_B = c(51.03, 
    51.1, 50.95, 50.49, 50.42, 50.6, 50.05, 50.4, 48.3, 48.25, 
    55.47, NA, 54.83, 55.49, 55.65, 61.04, 70.58, 70.34, 55.84, 
    55.76), Amag_GK30097_PI468340_Embrapa2_B = c(50.09, 50.08, 
    49.42, 48.87, 49.04, 49.01, 48.69, 48.51, 54.25, 54.3, 71.2, 
    54.83, NA, 65.05, 67.77, 53.05, 55.91, 55.97, 68.63, 65.83
    ), Avali_VP13514_Embrapa_B = c(49.08, 49.04, 48.77, 48.31, 
    48.17, 48.21, 48.08, 47.98, 56.16, 56.05, 65.8, 55.49, 65.05, 
    NA, 66.5, 53.53, 56.53, 56.65, 66.51, 71.14), Amag_VS13751_Embrapa_B = c(50.09, 
    49.94, 49.47, 49.11, 48.94, 49.05, 48.82, 48.7, 54.32, 54.47, 
    67.96, 55.65, 67.77, 66.5, NA, 53.55, 56.73, 56.75, 69.52, 
    67.38), Akemp_V14673_Embrapa_A = c(52.73, 52.65, 51.79, 52.01, 
    52.06, 52.02, 51.86, 52.26, 49.75, 49.59, 53.41, 61.04, 53.05, 
    53.53, 53.55, NA, 61.9, 62.04, 53.91, 54.01), Ahoeh_V14547_Embrapa_B = c(52.2, 
    52.22, 51.97, 51.57, 51.51, 51.49, 51.24, 51.38, 49.42, 49.45, 
    56.35, 70.58, 55.91, 56.53, 56.73, 61.9, NA, 73.08, 56.79, 
    57.01), Ahoeh_VP9140_PI666086_Embrapa_B = c(51.91, 52.07, 
    51.89, 51.42, 51.26, 51.31, 50.84, 51.04, 49.11, 49.29, 56.27, 
    70.34, 55.97, 56.65, 56.75, 62.04, 73.08, NA, 56.83, 57.09
    ), Amag_Se3777_IBONE_B = c(50.01, 50.01, 49.38, 49.04, 48.99, 
    49.08, 48.66, 48.71, 54.48, 54.53, 68.94, 55.84, 68.63, 66.51, 
    69.52, 53.91, 56.79, 56.83, NA, 67.45)), row.names = c(NA, 
20L), class = "data.frame")

Thank you!

(This post was formatted by forum moderation)

Thanks! Plugging this into my previous example app and replacing any reference to my first column (.) with your first column (Sample), everything seems to work and does not appear slow on my end. I'm guessing your app may have other calculations going on besides just generating these two tables. Is that the case?

Thank you for testing with the small data set. Here is your code where I only changed the distance matrix data:

library(shiny)
library(tidyverse)
library(kableExtra)

distance data

df <- read.table("D:/Affy/Affy_Bertioli_Lab/Affy15_PRO100992_UofGA992_SPR_b01/Allotetraploids/Allo_identity.txt", header = TRUE)
names(df)[1] <- "."

ui <- fluidPage(
br(),
fluidRow(
# column for inputs
column(2,
selectInput('from',
'From',
choices = df$.,
multiple = F,
width = '200px'),
selectInput('to',
'To',
choices = names(df)[names(df) != '.'],
multiple = F,
width = '200px')
),
# column for tables
column(10,
HTML('Filtered table output'),
br(),
tableOutput('table_filtered'),
br(),
br(),
HTML('Highlighted table output'),
br(),
tableOutput('table_highlighted')
)
)
)

server <- function(input, output, session) {

filtered table

output$table_filtered = renderTable({
req(input$from, input$to)

col = which(names(df) == input$to)

df %>%
  filter(. == input$from) %>%
  select_at(c(1, col))

})

highlighted table

output$table_highlighted = function() {
req(input$from, input$to)

myrow = which(df$. == input$from)
col = which(names(df) == input$to)

df[myrow,col] = paste0('<font style="background-color: yellow;">', df[myrow,col], '</font>')

kbl(df, 'html', escape = F, align = 'c') %>%
  kable_paper(full_width = F, position = 'left')  %>%
  column_spec(1:length(df), width = '5em')

}

}

shinyApp(ui, server)

It is working only taking quite a long to show results though, nevertheless, I can work with it.

Thank you! I really appreciate this.

It might be helpful for you to know how to properly format code and console output that you post here. Using proper code formatting makes the site easier to read, prevents confusion (unformatted code can get garbled by the forum software :anguished:), and is generally considered the polite thing to do. Check out this FAQ to find out how — it's as easy as the click of a button! :grinning::

One last thing to try. It seems like the final line of output$table_highlighted is causing the sluggish performance (it's setting the column width for all columns). Try commenting that out and see if it becomes more responsive.

# highlighted table
  output$table_highlighted = function() {
    req(input$from, input$to)
    
    myrow = which(df$. == input$from)
    col = which(names(df) == input$to)
    
    df[myrow,col] = paste0('<font style="background-color: yellow;">', df[myrow,col], '</font>')
    
    kbl(df, 'html', escape = F, align = 'c') %>%
      kable_paper(full_width = F, position = 'left')  #%>%
      # column_spec(1:length(df), width = '5em')
  }

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.