[Code]
library(shiny)
server <- function(input, output) {
output$iris_type <- renderDataTable({
data.frame(Species=paste0("<a href='#filtered_data'>", unique(iris$Species), "</a>"))
})
output$filtered_data <- renderDataTable({iris})
}
ui <- shinyUI(fluidPage(
mainPanel(
tabsetPanel(
tabPanel("Iris Type", dataTableOutput("iris_type")),
tabPanel("Filtered Data", dataTableOutput("filtered_data"))
)
)
))
shinyApp(ui = ui, server = server)
[Question]
I am trying to link the DataTable
output on first tab to the second tab. For example, when I click on setosa
, the next thing showing up is second tab with iris
dataset containing only setosa
. It should execute this piece of code from R: iris[iris$Species=="setosa",]
. It should work for other Species
in iris
too.
How can I build up the link and run that R command by clicking?
[Update on answer]
In case you have a different layout and needs to be specific, here is what you can do.
Your
DataTable
callback function:callback = "function(table) { table.on('click.dt', 'tr', function() { Shiny.onInputChange('rows', table.row(this).data()[0] ); $(\".tabbable .nav.nav-tabs li a:contains('Filtered Data')\").click(); }); }"
Your
R
code:output$filtered_data <- renderDataTable({ tagString <- input$rows rawTags <- gsub("</a>", "", gsub("<a href='#filtered_data'>", "", tagString)) if (identical(tagString, character(0))) { iris } else { ... } })