Commit de10e963 authored by Tuija Sonkkila's avatar Tuija Sonkkila

Replaces ggvis scatter to that of plotly

parent f356ea61
......@@ -3,8 +3,9 @@ function(input, output, session) {
# When school is selected, filter data with it
schoolData <- reactive({
data %>%
filter(parent %in% input$school)
if ( input$school == "All" ) return(data) else data[data$parent %in% input$school, ]
})
......@@ -13,96 +14,64 @@ function(input, output, session) {
observe(
updateSelectInput(session,
inputId = 'dept',
choices = sort(c("All", unique(schoolData()$name)))
choices = if ( input$school == "All" ) "Select school first" else c("All", sort(unique(schoolData()$name)))
)
)
# Filter school data by dept, if selected
deptData <- reactive({
if ( input$dept=="All" ) {
if ( is.null(input$dept) || input$dept == "Select school first" || input$dept == "All") {
return(schoolData())
}
isolate(schoolData() %>% filter(name %in% input$dept))
})
# TO DO replace ggvis with plotly
# because ggvis is not developed any longer
# and there's no geom_jitter
ggvisdata <- reactive({
show_title <- function(x=NULL) {
if(is.null(x)) return(NULL)
key <- x["keys"][[1]]
deptData()$title[key]
}
xvar_name <- input$xc
yvar_name <- input$yc
xscale <- input$scale
xc <- prop("x", as.symbol(input$xc))
yc <- prop("y", as.symbol(input$yc))
df <- deptData()
# Prepare URLs for datatable
makedata <- reactive({
df$keys <- seq_along(df[,1])
totable <- deptData()
df %>%
transform(evidence = factor(evidence)) %>%
ggvis(x = xc,
y = yc,
key := ~keys,
shape = ~evidence,
fill := ~color,
# stroke = ~stroke,
# strokeWidth := 3,
opacity := 0.70,
size.hover := 200) %>%
layer_points() %>%
group_by(evidence) %>%
hide_legend("stroke") %>%
add_axis("x",
title = xvar_name,
format = "d", # https://github.com/d3/d3-format#locale_format
grid = FALSE,
title_offset = 50,
tick_padding = 7,
offset = 10,
properties = axis_props(
labels=list(
angle = 50,
fontSize = 10))) %>%
add_axis("y",
title = yvar_name,
title_offset = 50) %>%
set_options(width = "100%",
height = "600px",
renderer = "canvas") %>%
add_tooltip(show_title) %>%
scale_numeric(property = "x",
trans = xscale,
expand=0)
totable <- totable %>%
mutate(url = paste0("<a target='blank' href='http://dx.doi.org/", doi, "'>", doi, "</a>"),
oa_url = ifelse(!is.na(urls),
paste0("<a target='blank' href='", urls, "'>", urls, "</a>"),
urls)) %>%
select(url, title, year, times_cited, times_cited_wos, recent_citations, relative_citation_ratio, field_citation_ratio,
authors, oa, is_oa, oa_url, fieldcount, parent, name)
})
ggvisdata %>% bind_shiny("gv")
makedata <- reactive({
output$plotly <- renderPlotly({
totable <- deptData()
df <- deptData()
totable <- totable %>%
mutate(url = paste0("<a target='blank' href='http://dx.doi.org/", doi, "'>", doi, "</a>"),
oa_url = ifelse(!is.na(free_fulltext_url),
paste0("<a target='blank' href='", free_fulltext_url, "'>", free_fulltext_url, "</a>"),
free_fulltext_url)) %>%
select(url, title, year, times_cited, recent_citations, relative_citation_ratio, field_citation_ratio,
authors, oa, units, fieldcount, name, evidence, oa_url)
colors <- df$color
df$xx <- df[[input$xc]]
df$yy <- df[[input$yc]]
p <- plot_ly(df,
type = "scatter",
x = ~xx,
y = ~yy,
mode = "markers",
hoverinfo = "text",
colors = colors,
color = I(colors),
split = ~parent,
symbol = ~symbol,
marker = list(size = 10, opacity = 0.7),
hovertext = ~text,
textposition = "middle right") %>%
layout( xaxis = list( title=input$xc),
yaxis = list( title=input$yc ) )
})
......@@ -115,9 +84,9 @@ function(input, output, session) {
extensions = "FixedHeader",
options = list(paging = TRUE,
fixedHeader = TRUE,
autoWidth = TRUE, # https://stackoverflow.com/a/31814197
columnDefs = list(list(width = '150px', targets = "_all"))))
autoWidth = TRUE,
scrollX = TRUE,
columnDefs = list(list(target = "_all", width = "50px"))))
return(dat)
})
......
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