Hello,
I have made a data frame called "df", which lists Gene1, Gene2, and their correlation value. It comes from my file "Correlations.csv". When a user clicks a row of this datatable, the Shiny app references a background data frame called Expression (I load this in from my file "Expression.rds"). The Expression data frame contains expression values for Gene1 and Gene2 listed on the row from df that the user selected, and it renders a plot to the right side of the data table (see image below).
As much as I've tried with the splitLayout feature, I can't seem to find a way to adjust the plot position to appear where I want it. It aligns with the top of the data table, but I want it aligned with the bottom (or maybe at least centered).
Currently what I have :
library(shiny)
library(tidyverse)
library(ggplot2)
library(DT)
df <- read_csv("Correlations.csv")
Expression <- read_rds("Expression.rds")
# Define UI for application that creates a datatables
ui <- fluidPage(#fluidRow(column(12, div(dataTableOutput("dataTable")))),
# First Row
# Show a plot of the generated distribution
splitLayout(DT::dataTableOutput("fancyTable"),
plotOutput("plot")
), # end of main panel
# Second Row
#fluidRow(
# column(12, offset = 0, htmlOutput("network"))
#)
#fluidRow(column(width = 12, plotOutput("network")))
) # end of fluid page
# Define UI for application that creates a datatables
#ui <- splitLayout(cellWidths = c("65%", "30%"),
# DT::dataTableOutput("fancyTable"),
# plotOutput("plot")
#
#)
# Define server logic required to create datatable
server <- function(input, output, session) {
myCSV <- reactive({
# read.csv(input$TheFile)
df
})
output$fancyTable <- DT::renderDataTable(
datatable( 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
# customize the length menu
, lengthMenu = list( c(10, 20, -1) # declare values
, c(10, 20, "All") # declare titles
) # end of lengthMenu customization
, pageLength = 10
) # end of options
) # end of datatables
)
observe({
req(input$fancyTable_rows_selected)
selRow <- myCSV()[input$fancyTable_rows_selected,]
print(selRow[[1]])
output$plot <- renderPlot({
ggplot(Expression, aes_string(x=selRow[[1]], y=selRow[[2]])) +
geom_point(size=2) +
geom_smooth(method=lm, size=2) +
geom_rug(col="darkred", size=0.9, sides="bl", alpha = 0.3) +
theme(aspect.ratio = 1,
axis.title = element_text(size = 15, face = "bold", color = "black"),
axis.text = element_text(size = 12, face = "bold", color = "black"))
})
})
} # end of server
# Run the application
shinyApp(ui = ui, server = server)
Relevant images:
Thanks for any help and guidance!