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

Removed unused directories.

parent 68493698
read_data <- function(path, header, sep, quote) {
tryCatch(
{
df <- read.csv(path,
header,
sep,
quote)
},
error = function(e) {
## return a safeError if a parsing error occurs
stop(safeError(e))
}
)
return(df)
}
save_settings <- function(settings, path) {
json_settings = toJSON(settings)
print(path)
# if (!grepl('.*\\.json$', json_settings) ) {
# path = paste0(path,'.json')
# }
write(json_settings, path, append = FALSE)
print('downloaded')
}
read_settings <- function(path){
json_data <- fromJSON(file = path)
return(json_data)
}
test_settings_io <- function()
{
path = 'C:/Users/meechan/Documents/settings.json'
save_settings(c('a','b'), path)
read_settings(path)
}
getSettings <- function( s ) {
if ( exists("s") && !is.null(s) ) {
return(s)
} else {
return(NULL)
}
}
\ No newline at end of file
This diff is collapsed.
library(shiny)
ui <- basicPage(
plotOutput("plot1",
click = "plot_click",
dblclick = "plot_dblclick",
hover = "plot_hover",
brush = "plot_brush"
),
verbatimTextOutput("info")
)
server <- function(input, output) {
library(png)
prev_vals <- NULL
structures <- reactiveValues(data = data.frame(box_id = numeric(), xmin = numeric(), ymin = numeric(), xmax = numeric(), xmax = numeric()))
output$plot1 <- renderPlot({
img <- readPNG("canonical_mitotic_cell.png", native = TRUE)
plot(1:640, type='n')
rasterImage(img,1,1,640,640)
if (nrow(structures$data) > 0) {
r <- structures$data
rect(r$xmin, r$ymin, r$xmax, r$ymax, border = "red")
}
}, height = 640, width = 640)
observe({
e <- input$plot_brush
if (!is.null(e)) {
vals <- data.frame(xmin = round(e$xmin, 1), ymin = round(e$ymin, 1), xmax = round(e$xmax, 1), ymax = round(e$ymax, 1))
if (identical(vals,prev_vals)) return() #We dont want to change anything if the values havent changed.
structures$data <- rbind(structures$data,cbind(data.frame(box_id = nrow(structures$data)+1),vals))
prev_vals <<- vals
}
})
output$info <- renderText({
xy_str <- function(e) {
if(is.null(e)) return("NULL\n")
paste0("x=", round(e$x, 1), " y=", round(e$y, 1), "\n")
}
xy_range_str <- function(e) {
if(is.null(e)) return("NULL\n")
paste0("xmin=", round(e$xmin, 1), " xmax=", round(e$xmax, 1),
" ymin=", round(e$ymin, 1), " ymax=", round(e$ymax, 1))
}
paste0(
"click: ", xy_str(input$plot_click),
"dblclick: ", xy_str(input$plot_dblclick),
"hover: ", xy_str(input$plot_hover),
"brush: ", xy_range_str(input$plot_brush)
)
})
}
shinyApp(ui, server)
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