i am developing a web interface to visualize circos plots with shiny.gosling. my desire is to make dynamic filtering in order to make the user free to select a particular class to plot. i understood how to accomplish that with shiny but not in shiny.gosling. Can someone help me please?
here a toy script:
library(shiny)
library(shiny.gosling)
library(shiny.react)
library(shinythemes)
library(shinyjs)
use_gosling()
library(GenomicRanges)
ui <- navbarPage(
title = 'visualizer',
tabPanel(
'Circos',
use_gosling(),
fluidRow(
column(4, goslingOutput('gosling_plot')),
column(1, br(), actionButton('download_pdf', 'PDF', icon = icon('cloud-arrow-down'))),
column(5,
br(),
selectInput(
inputId = 'classSelect',
label = 'Class:',
choices = unique(data_cnv_met$class)
)
)
)
),
theme = shinytheme('united'),
use_gosling()
)
server <- function(input, output, session) {
data <- eventReactive(input$classSelect, {
selectedClass <- input$classSelect
filtered_df <- data_cnv_met[data_cnv_met$class == selectedClass, ]
data_gr <- makeGRangesFromDataFrame(filtered_df, seqnames.field = 'chr', start.field = 'start', end.field = 'end', keep.extra.columns = TRUE, na.rm = TRUE)
return(data_gr)
})
output$gosling_plot <- renderGosling({
gosling(component_id = "gosling_plot", data())
})
observeEvent(input$download_pdf, {
export_pdf(component_id = "gosling_plot")
})
}
track_coefs <- add_single_track(
data = track_data_gr(data_gr, chromosomeField = 'seqnames',
genomicFields = c('start', 'end')
),
mark = 'bar',
x = visual_channel_x(
field = 'start', type = 'genomic', axis = 'bottom'
),
xe = visual_channel_x(
field = 'end', type = 'genomic', axis = 'bottom'
),
y = visual_channel_y(
field = 'coef', type = 'quantitative', axis = 'none'
),
color = 'red',
tooltip = visual_channel_tooltips(
visual_channel_tooltip(field = "start", type = "genomic",
alt = 'Start Position:'),
visual_channel_tooltip(field = "end", type = "genomic",
alt = "End Position:"),
visual_channel_tooltip(
field = "coef",
type = "quantitative",
alt = "Coefficient Value:",
format = "0.2"),
visual_channel_tooltip(
field = "class",
type = "nominal",
alt = "Class:",
format = "0.2"),
visual_channel_tooltip(
field = 'gene',
type = 'nominal',
alt = 'Gene Name:'
)
),
size = list(value = 2)
)
composed_view <- compose_view(
layout = 'linear', #linear
tracks = track_coefs
)
arranged_view <- arrange_views(
title = 'gosling_plot',
subtitle = 'subtitle',
views = composed_view,
xDomain = list(
chromosome = 'chr1'
)
)
shiny::shinyApp(ui, server)