Commit 1b169028 authored by Jean-Karim Heriche's avatar Jean-Karim Heriche

Merge branch 'patch-2' into 'master'

New version of cell_explorer.shiny.R to illustrate the 3-panel UI

See merge request !5
parents 5527d4f5 8c43d4ed
library(DT) ## R interface to the js DataTables library
library(EBImage) ## already has shiny integration functions
library(shiny)
library(shinyFiles)
ui <- fluidPage(
ui <- fluidPage(
titlePanel("Input files", windowTitle = "Cell Explorer"),
## Sidebar layout with input and output definitions
sidebarLayout(
position = c("left", "right"),
fluid = TRUE,
## Sidebar panel for inputs
sidebarPanel(
width = 3,
## Input: Select a file
fileInput("datafile", "Select data file (in CSV format)",
fileInput("datafile", "Select data file",
multiple = FALSE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
## Horizontal line
tags$hr(),
## Input: Checkbox if file has header
checkboxInput("header", "File has header", TRUE),
......@@ -40,34 +42,67 @@ ui <- fluidPage(
"Single Quote" = "'"),
selected = '"'),
tags$hr(),
## Horizontal line
tags$hr(style="border-top: 1px solid #000000;"),
## Select variables to display
uiOutput("variables")
uiOutput("variables"),
tags$hr(style="border-top: 1px solid #000000;"),
),
## Select image root directory
shinyDirButton('dir',
label='Select image root dir',
title=''),
tags$br(),tags$br(),
"Selected image directory:",
tags$br(),
verbatimTextOutput('imageDir')
),
## Main panel for displaying outputs
mainPanel(
## Output: Data file
DTOutput("content")
mainPanel(
width = 9,
fluidRow(
column(9,
h3('Plot'),
plotOutput('plot', height = 500),
verbatimTextOutput('x4')
)
),
fluidRow(
column(9,
tabsetPanel(
tabPanel(
## Output : Data file
h3('Data'),
DTOutput("content")
),
tabPanel(
h3('Image'),
displayOutput("widget")
)
)
)
),
tags$hr(),
h1('Plot'),
plotOutput('plot', height = 500),
verbatimTextOutput('x4')
)
)
)
)
server <- function(input, output) {
## Increase max upload size to 500 MB
options(shiny.maxRequestSize=500*1024^2)
roots = c(home = "~", wd='.')
shinyDirChoose(input, 'dir', roots = roots)
output$imageDir <- renderText({
dirInfo <- parseDirPath(roots, input$dir)
})
data <- reactive({
......@@ -97,8 +132,8 @@ server <- function(input, output) {
## Dynamically generate UI input when data is uploaded
output$variables <- renderUI({
checkboxGroupInput(inputId = "selected_var",
label = "Select variables to plot",
checkboxGroupInput(inputId = "selectedVar",
label = "Variables to plot",
choices = names(data()))
})
......@@ -106,27 +141,29 @@ server <- function(input, output) {
## Highlight selected rows in the plot
output$plot = renderPlot({
selected_rows <- input$content_rows_selected
selected_cols <- input$selected_var
selectedRows <- input$content_rows_selected
selectedCols <- input$selectedVar
par(mar = c(4, 4, 1, .1))
D <- data()
## Limit selection to two columns otherwise we get a scatterplot matrix
if (length(selected_cols) == 2) {
plot(D[,selected_cols])
if (length(selectedCols) == 2) {
plot(D[,selectedCols])
}
if (length(selected_rows)) {
points(D[selected_rows, selected_cols], pch = 19, cex = 1, col = "red")
if (length(selectedRows)) {
points(D[selectedRows, selectedCols], pch = 19, cex = 1, col = "red")
}
})
output$x4 = renderPrint({
s = input$selected_var
s = input$selectedVar
if (length(s)) {
cat('These variables were selected:\n\n')
cat(s, sep = ', ')
}
})
image.file <- '/home/heriche/canonical_mitotic_cell.png'
img <- reactive({
readImage(image.file)
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment