Please help - Adding another dataset for my shiny app to reference?

  • The purpose of my Shiny app is to take two genes which are correlated (A and B) for example, and display their correlation value (rho) and statistical value (Adj_p) in a table. This information is stored in df_SET1.

  • When a user clicks a row of the table, the corresponding expression values corresponding to that row (A and B, for example) are looked up in the background dataframe Expression_SET1 and a scatterplot is made for those values across all samples.

The result works nicely and looks like this :

My question: How can I allow a user to now select a different set of data but still have the app work?

For example - at the top how could I insert some dropdown menu to display "SET1" and also "SET2" - such that if a user now selects SET2 then df_SET2 and Expression_SET2 are loaded and the app is based off this instead of the SET1 datasets?


## Define UI for application that creates a datatables

body <- dashboardBody(
      # The id lets us use input$tabset1 on the server to find the current tab
      id = "tabset1", height = "400px",
      tabPanel("Data", DT::dataTableOutput("fancyTable"))
      side = "right", height = "580px",
      selected = "Scatterplot",
      tabPanel("Scatterplot", plotlyOutput("plot", height="480px"))

## Define Server logic required to create datatable
server <- function(input, output, session) {
  addClass(selector="body", class="sidebar-collapse")
  myCSV <- reactive({df_SET1}) # read.csv(input$TheFile)
  # Panel 1: 
  output$fancyTable <- DT::renderDataTable(
      data = myCSV(), extensions = 'Buttons', selection = 'single',
      options = list(
        dom = "Blfrtip",
        buttons = list("copy", list(extend = "collection", buttons = c("csv", "excel", "pdf"), text = "Download")), # end of buttons customization
        lengthMenu = list(c(10, 20, -1), c(10, 20, "All")), # customize the length menu: declare values and titles
        pageLength = 10
      ) # end of options
    ) # end of datatables
  # Panel 2:
    selRow <- myCSV()[input$fancyTable_rows_selected,]
    output$plot <- renderPlotly({
      ggplot(Expression_SET1, aes_string(x=selRow[[1]], y=selRow[[2]])) +labs(x=paste("Log2_Expression:",selRow[[1]]), y=paste("Log2_Expression:",selRow[[2]]))+
        geom_point(aes(text=paste(Expression_SET1$X1)),size=1.3) + 
        geom_smooth(method=lm, size=1.3) + 
        geom_rug(col="darkred", size=0.9, sides="bl", alpha = 0.3) +
        theme(aspect.ratio = 1,
              axis.title = element_text(size = 10.5, face = "bold", color = "black"),
              axis.text = element_text(size = 10.5, face = "bold", color = "black")
} # end of server

# Run the application
shinyApp(  ui = dashboardPage(
), server = server)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.