Commit c2ce4130 authored by Jean-Karim Heriche's avatar Jean-Karim Heriche

Uploaded cell_explorer.R

parent 6b82ee98
library(DT) ## R interface to the js DataTables library
library(EBImage) ## already has shiny integration functions
library(shiny)
ui <- fluidPage(
titlePanel("Input files", windowTitle = "Cell Explorer"),
## Sidebar layout with input and output definitions
sidebarLayout(
## Sidebar panel for inputs
sidebarPanel(
## Input: Select a file
fileInput("datafile", "Select data file (in CSV format)",
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),
## Input: Select separator
radioButtons("sep", "Separator",
choices = c(Comma = ",",
Semicolon = ";",
Tab = "\t"),
selected = "\t"),
## Input: Select quotes
radioButtons("quote", "Quote",
choices = c(None = "",
"Double Quote" = '"',
"Single Quote" = "'"),
selected = '"'),
tags$hr(),
## Select variables to display
uiOutput("variables")
),
## Main panel for displaying outputs
mainPanel(
## Output: Data file
DTOutput("content")
)
),
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)
data <- reactive({
if (is.null(input$datafile)) return(NULL)
## After the user selects and uploads a data file,
## the content of the data file will be shown.
req(input$datafile)
## When reading semicolon separated files,
## having a comma separator causes `read.csv` to error
tryCatch(
{
df <- read.csv(input$datafile$datapath,
header = input$header,
sep = input$sep,
quote = input$quote)
},
error = function(e) {
## return a safeError if a parsing error occurs
stop(safeError(e))
}
)
return(df)
})
## Dynamically generate UI input when data is uploaded
output$variables <- renderUI({
checkboxGroupInput(inputId = "selected_var",
label = "Select variables to plot",
choices = names(data()))
})
output$content <- renderDT(data(), server = TRUE)
## Highlight selected rows in the plot
output$plot = renderPlot({
selected_rows <- input$content_rows_selected
selected_cols <- input$selected_var
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(selected_rows)) {
points(D[selected_rows, selected_cols], pch = 19, cex = 1, col = "red")
}
})
output$x4 = renderPrint({
s = input$selected_var
if (length(s)) {
cat('These variables were selected:\n\n')
cat(s, sep = ', ')
}
})
img <- reactive({
readImage(image.file)
})
## Interactive image display with EBImage
output$widget <- renderDisplay({
display(img(), method = 'browser')
})
}
## Run the application
shinyApp(ui = ui, server = server, options = list("port" = 4722))
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