0

I have the shiny app below in which when I click on a row of the 1st table I should get the correspondent value of species column. Then with this value I should subset the second dataframe df based on its species column.

library(shiny)
library(DT)
shinyApp(
  ui = fluidPage(DT::dataTableOutput('tableId'),
                 dataTableOutput("celltext")),
  server = function(input, output) {
    output$tableId = DT::renderDataTable(
      iris[,c(1,5)],  selection = list(target = 'row',mode="single")
    )
     species<-c("setosa","setosa","virginica","virginica")
     flower<-c("a","b","c","d")
     score<-c(7,5,6,9)
     df<-data.frame(species,flower,score)
    output$celltext <- renderDataTable({
      cell <- input$tableId_rows_selected
      df<-df[df$species == iris[row]
    })
  }
)
firmo23
  • 7,490
  • 2
  • 38
  • 114

1 Answers1

1

Try this

shinyApp(
  ui = fluidPage(DT::dataTableOutput('tableId'),
                 DTOutput("celltext")),
  server = function(input, output) {
    output$tableId = DT::renderDataTable(
      iris[,c(1,5)],  selection = list(target = 'row',mode="single")
    )
    species<-c("setosa","setosa","virginica","virginica")
    flower<-c("a","b","c","d")
    score<-c(7,5,6,9)
    df<-data.frame(species,flower,score)
    
    output$celltext <- renderDT({
      cell <- input$tableId_rows_selected
      dat<-df[df$species %in% iris[cell,5],]
      dat
    })
  }
)
YBS
  • 19,324
  • 2
  • 9
  • 27
  • check this out based on your answer please. https://stackoverflow.com/questions/65674603/use-actionbutton-to-move-to-the-next-row-of-dataframe-in-a-shiny-app – firmo23 Jan 11 '21 at 21:13