0

In my Shiny App, I am attempting to use the DT package to take an input from table A and use it to filter data in table B. However, only data from column 0 in table A is applicable as the filter value. Hence, if one clicks on column 1, the output in table B comes out empty.

My question is then, whether it is possible to force the cell_clicked suffix to always return the value from column 0, from the row that is clicked on? Essentially i would like to return input$tabelA_cell-clicked$value where column number is equal to 0 and rownumber is equal to input$tabelA_cell_clicked$row

I have attempted the following in the serverscript (Simplified example):

output$tabelA <- renderDataTable({datatable(Data_tabel_A)})

output$TabelB <- renderDataTable({datatable(Data_tabel_B %>%
                                 filter(variable1 == input$tabelA[input$tabelA_cell_clicked$row,0]))
})

However, input$tabelA[input$tabelA_cell_clicked$row,0] does not appear to return a value. Can anybody point me in the right direction?

  • Your post is certainly above average for a newcomer but still without a reproducible example people won't be able to help you. Especially with shiny, it can take a lot of coding to demo simple things so people will avoid such questions if you don't provide some minimum working code. See [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Shree Nov 02 '18 at 15:04

1 Answers1

1

Following up on my comment, since you did not provide a reproducible code, here's a simple demo using iris data set -

library(shiny)
library(DT)

shinyApp(
  ui = fluidPage(
    splitLayout(
      DTOutput("table_A"),
      DTOutput("table_B")
    )
  ),
  server = function(input, output, session) {

    # can be reactive
    table_A_data <- data.frame(Species = unique(iris$Species),
                               SomeColumn1 = letters[1:3],
                               SomeColumn2 = 1:3)

    output$table_A <- renderDT({
        datatable(table_A_data, selection = 'single')
    })

    output$table_B <- renderDT({
      req(input$table_A_rows_selected)
      # since I want to use only species value for filtering
      filter_val <- table_A_data$Species[input$table_A_rows_selected]
      iris %>%
        filter(Species == filter_val) %>%
        datatable()
    })
  }
)
Shree
  • 10,835
  • 1
  • 14
  • 36
  • Hey Shree, thanks for the quick reply and your patience with a newbie. I will make sure to add a reproducible example for future posts. – Earlowich Nov 02 '18 at 15:36
  • No problem. If this answer solved your problem then consider marking it as correct using the tick mark at the top left of this answer. – Shree Nov 02 '18 at 15:37