datatables - R shiny build links between tabs with DT package -


solution creating links between tabs have found here r shiny build links between tabs nice, it's not working dt package (for me..). can tell me, doing wrong in example code using dt library in compare solution without dt package?

library(shiny) library(dt)  server <- function(input, output) {     output$iris_type <- dt::renderdatatable({         datatable(data.frame(species=paste0("<a href='#filtered_data'>", unique(iris$species), "</a>")),                   escape = false,                   options = list(initcomplete = js( 'function(table) {     table.on("click.dt", "tr", function() {     shiny.oninputchange("rows", table.row( ).index());     tabs = $(".tabbable .nav.nav-tabs li a");     $(tabs[1]).click();     }); }')))     })    output$filtered_data <- dt::renderdatatable({       if(is.null(input$rows)){           iris       }else{           iris[iris$species %in% unique(iris$species)[as.integer(input$rows)+1], ]       }       })   }  ui <- shinyui(fluidpage(     mainpanel(         tabsetpanel(             tabpanel("iris type", dt::datatableoutput("iris_type")),             tabpanel("filtered data", dt::datatableoutput("filtered_data"))         )     ) ))  shinyapp(ui = ui, server = server) 

you try code below. changed function switching tabs callback (which has table argument) , in output$filtered_data, replaced iris datable(iris) since rendering dt::renderdatatable

library(shiny) library(dt)  server <- function(input, output) {   output$iris_type <- dt::renderdatatable({     datatable(data.frame(species=paste0("<a href='#filtered_data'>", unique(iris$species), "</a>")),               escape = false,               callback = js(                 'table.on("click.dt", "tr", function() {     tabs = $(".tabbable .nav.nav-tabs li a");     $(tabs[1]).click();})'))   })    output$filtered_data <- dt::renderdatatable({     selected <- input$iris_type_rows_selected     if(is.null(selected)){       datatable(iris)     } else {       datatable(iris[iris$species %in% unique(iris$species)[selected], ])     }   }) }  ui <- shinyui(fluidpage(   mainpanel(     tabsetpanel(       tabpanel("iris type", dt::datatableoutput("iris_type")),       tabpanel("filtered data", dt::datatableoutput("filtered_data"))     )   ) ))  shinyapp(ui = ui, server = server) 

please note requires dt >= 0.0.62.


Comments

Popular posts from this blog

php - How can an email be returned from Stripe Checkout? -

SQL php on different pages to Insert (mysqli) -

linked list - Get the index of the Node in a LinkedList which contains the given value in java -