Skip to content

Instantly share code, notes, and snippets.

@tts
Created July 3, 2014 12:49
Show Gist options
  • Save tts/a41c8581b9d77f131b31 to your computer and use it in GitHub Desktop.
Save tts/a41c8581b9d77f131b31 to your computer and use it in GitHub Desktop.
Simplified ggvis Shiny example with sample data, see http://stackoverflow.com/questions/24554734/dynamic-ggvis-object-in-shiny
doi school ti au url details_url py j9 so tc score mendeley connotea citeulike readers_count cited_by_gplus_count cited_by_fbwalls_count cited_by_posts_count cited_by_tweeters_count cited_by_accounts_count cited_by_feeds_count cited_by_videos_count cited_by_delicious_count cited_by_rdts_count cited_by_forum_count cited_by_qs_count cited_by_rh_count cited_by_msm_count
10.1001/jama.2012.347 SCI One vs Three Years of Adjuvant Imatinib for Operable Gastrointestinal Stromal Tumor A Randomized Trial Joensuu, H; Eriksson, M; Hall, KS; Hartmann, JT; Pink, D; Schutte, J; Ramadori, G; Hohenberger, P; Duyster, J; Al-Batran, SE; Schlemmer, M; Bauer, S; Wardelmann, E; Sarlomo-Rikala, M; Nilsson, B; Sihto, H; Monge, OR; Bono, P; Kallio, R; Vehtari, A; Leinonen, M; Alvegard, T; Reichardt, P http://dx.doi.org/10.1001/jama.2012.347 http://www.altmetric.com/details.php?citation_id=670011 2012 JAMA-J AM MED ASSOC JAMA-JOURNAL OF THE AMERICAN MEDICAL ASSOCIATION 106 4.75 52 0 1 53 NA 1 7 5 7 NA NA NA NA NA NA 1 NA
10.1002/acp.2918 BIZ Attention and Memory for Newspaper Advertisements: Effects of Ad-Editorial Congruency and Location Simola, J; Kivikangas, M; Kuisma, J; Krause, CM http://onlinelibrary.wiley.com/doi/10.1002/acp.2918/abstract http://www.altmetric.com/details.php?citation_id=1302496 2013 APPL COGNITIVE PSYCH APPLIED COGNITIVE PSYCHOLOGY 2 1.75 2 0 0 2 NA NA 1 4 4 NA NA NA NA NA NA NA NA
10.1002/adfm.201102827 SCI Simplified Large-Area Manufacturing of Organic Electrochemical Transistors Combining Printing and a Self-Aligning Laser Ablation Step Blaudeck, T; Ersman, PA; Sandberg, M; Heinz, S; Laiho, A; Liu, J; Engquist, I; Berggren, M; Baumann, RR http://dx.doi.org/10.1002/adfm.201102827 http://www.altmetric.com/details.php?citation_id=704569 2012 ADV FUNCT MATER ADVANCED FUNCTIONAL MATERIALS 5 10 16 0 0 16 NA NA 2 1 2 NA NA NA NA NA NA NA 1
10.1002/adfm.201201528 SCI Epitaxial Ferroelectric Heterostructures with Nanocolumn-Enhanced Dynamic Properties Tyunina, M; Yao, LD; Plekh, M; Levoska, J; van Dijken, S http://onlinelibrary.wiley.com/resolve/doi?DOI=10.1002%2Fadfm.201201528&utm_source=dlvr.it&utm_medium=twitter http://www.altmetric.com/details.php?citation_id=928305 2013 ADV FUNCT MATER ADVANCED FUNCTIONAL MATERIALS 4 0.5 4 0 0 4 NA 1 2 1 2 NA NA NA NA NA NA NA NA
10.1002/adma.201100461 CHEM Superhydrophobic Tracks for Low-Friction, Guided Transport of Water Droplets Mertaniemi, H; Jokinen, V; Sainiemi, L; Franssila, S; Marmur, A; Ikkala, O; Ras, RHA http://dx.doi.org/doi:10.1002/adma.201100461 http://www.altmetric.com/details.php?citation_id=211781 2011 ADV MATER ADVANCED MATERIALS 29 9.25 22 0 0 22 NA NA 3 NA 2 1 1 NA NA NA NA NA NA
10.1002/adma.201101888 ELEC Optical Interference Lithography Using Azobenzene-Functionalized Polymers for Micro- and Nanopatterning of Silicon Kravchenko, A; Shevchenko, A; Ovchinnikov, V; Priimagi, A; Kaivola, M http://onlinelibrary.wiley.com/resolve/doi?DOI=10.1002/adma.201101888 http://www.altmetric.com/details.php?citation_id=240542 2011 ADV MATER ADVANCED MATERIALS 28 0.25 24 0 2 26 NA NA 1 1 1 NA NA NA NA NA NA NA NA
10.1002/adma.201103111 SCI Controlling Water Capture of Bioinspired Fibers with Hump Structures Tian, XL; Chen, Y; Zheng, YM; Bai, H; Jiang, L http://dx.doi.org/10.1002/adma.201103111 http://www.altmetric.com/details.php?citation_id=437073 2011 ADV MATER ADVANCED MATERIALS 13 9.25 11 0 0 11 NA NA 2 1 2 NA NA NA NA NA NA NA 1
10.1002/adma.201103131 SCI Controlling the Dimensionality of Charge Transport in an Organic Electrochemical Transistor by Capacitive Coupling Larsson, O; Laiho, A; Schmickler, W; Berggren, M; Crispin, X http://onlinelibrary.wiley.com/resolve/doi?DOI=10.1002/adma.201103131 http://www.altmetric.com/details.php?citation_id=419722 2011 ADV MATER ADVANCED MATERIALS 6 0.25 32 0 0 32 NA NA 1 1 1 NA NA NA NA NA NA NA NA
10.1002/adma.201200501 SCI Two-Dimensional Nanostructured Growth of Nanoclusters and Molecules on Insulating Surfaces Barth, C; Gingras, M; Foster, AS; Gulans, A; Felix, G; Hynninen, T; Peresutti, R; Henry, CR http://dx.doi.org/10.1002/adma.201200501 http://www.altmetric.com/details.php?citation_id=743967 2012 ADV MATER ADVANCED MATERIALS 1 15.592 17 0 0 17 NA 1 6 3 6 1 NA NA NA NA NA NA 1
10.1002/adma.201200931 ELEC Wire Metamaterials: Physics and Applications Simovski, CR; Belov, PA; Atrashchenko, AV; Kivshar, YS http://dx.doi.org/10.1002/adma.201200931 http://www.altmetric.com/details.php?citation_id=1506819 2012 ADV MATER ADVANCED MATERIALS 30 7 64 0 0 64 NA NA 1 NA 1 NA NA NA NA NA NA NA 1
10.1002/adma.201202549 SCI Self-Organized Origami Structures via Ion-Induced Plastic Strain Chalapat, K; Chekurov, N; Jiang, H; Li, J; Parviz, B; Paraoanu, GS http://dx.doi.org/10.1002/adma.201202549 http://www.altmetric.com/details.php?citation_id=1008805 2013 ADV MATER ADVANCED MATERIALS 2 21.25 43 0 0 43 1 2 9 2 9 1 1 NA 1 NA NA NA 1
10.1002/adma.201202980 SCI Rebounding Droplet-Droplet Collisions on Superhydrophobic Surfaces: from the Phenomenon to Droplet Logic Mertaniemi, H; Forchheimer, R; Ikkala, O; Ras, RHA http://dx.doi.org/10.1002/adma.201202980 http://www.altmetric.com/details.php?citation_id=934084 2012 ADV MATER ADVANCED MATERIALS 10 60.042 27 0 0 27 3 1 36 20 32 3 2 NA 1 NA NA NA 2
10.1002/adma.201204060 SCI Photoalignment and Surface-Relief-Grating Formation are Efficiently Combined in Low-Molecular-Weight Halogen-Bonded Complexes Priimagi, A; Saccone, M; Cavallo, G; Shishido, A; Pilati, T; Metrangolo, P; Resnati, G http://dx.doi.org/10.1002/adma.201204060 http://www.altmetric.com/details.php?citation_id=1521259 2012 ADV MATER ADVANCED MATERIALS 14 7 10 0 0 10 NA NA 1 NA 1 NA NA NA NA NA NA NA 1
10.1002/adma.201204696 ELEC Controlling Liquid Spreading Using Microfabricated Undercut Edges Liimatainen, V; Sariola, V; Zhou, Q http://dx.doi.org/10.1002/adma.201204696 http://www.altmetric.com/details.php?citation_id=1300533 2013 ADV MATER ADVANCED MATERIALS 2 10 22 0 0 22 NA NA 3 1 2 NA NA NA NA NA NA NA 1
10.1016/j.jbankfin.2013.01.042 SCI Drivers of holding period firm-level returns in private equity-backed buyouts Valkama, P; Maula, M; Nikoskelainen, E; Wright, M http://www.sciencedirect.com/science/article/pii/S0378426613000757 http://www.altmetric.com/details.php?citation_id=1272796 2013 J BANK FINANC JOURNAL OF BANKING & FINANCE 0 1 8 0 0 8 NA NA 1 1 1 NA NA NA NA NA NA NA NA
10.1016/j.jbusres.2012.04.004 BIZ Creating novel consumer value vs. capturing value: Strategic emphases and financial performance implications Aspara, J; Tikkanen, H http://www.sciencedirect.com/science/article/pii/S0148296312001129 http://www.altmetric.com/details.php?citation_id=1615643 2013 J BUS RES JOURNAL OF BUSINESS RESEARCH 0 0.25 26 0 0 26 NA 1 1 NA 1 NA NA NA NA NA NA NA NA
10.1016/j.jbusvent.2012.12.001 BIZ Narrative attributions of entrepreneurial failure Mantere, S; Aula, P; Schildt, H; Vaara, E http://dx.doi.org/10.1016/j.jbusvent.2012.12.001 http://www.altmetric.com/details.php?citation_id=1529611 2013 J BUS VENTURING JOURNAL OF BUSINESS VENTURING 0 0.25 44 0 0 44 NA NA 1 1 1 NA NA NA NA NA NA NA NA
10.1016/j.jcat.2013.08.027 CHEM The activity of ALD-prepared PtCo catalysts for ethanol oxidation in alkaline media Santasalo-Aarnio, A; Sairanen, E; Aran-Ais, RM; Figueiredo, MC; Hua, J; Feliu, JM; Lehtonen, J; Karinen, R; Kallio, T http://www.sciencedirect.com/science/article/pii/S0021951713003175 http://www.altmetric.com/details.php?citation_id=1799013 2014 J CATAL JOURNAL OF CATALYSIS 0 0.25 6 0 0 6 NA NA 1 1 1 NA NA NA NA NA NA NA NA
10.1021/ct400813d SCI Critical Importance of van der Waals Stabilization in Strongly Chemically Bonded Surfaces: Cu(110):O Bamidele, J; Brndiar, J; Gulans, A; Kantorovich, L; Stich, I http://dx.doi.org/10.1021/ct400813d http://www.altmetric.com/details.php?citation_id=1909772 2013 J CHEM THEORY COMPUT JOURNAL OF CHEMICAL THEORY AND COMPUTATION 0 1 4 0 0 4 NA NA 1 1 1 NA NA NA NA NA NA NA NA
10.1021/ct401016x SCI Pipek-Mezey Orbital Localization Using Various Partial Charge Estimates Lehtola, S; Jonsson, H http://pubs.acs.org/doi/abs/10.1021/ct401016x http://www.altmetric.com/details.php?citation_id=2052366 2014 J CHEM THEORY COMPUT JOURNAL OF CHEMICAL THEORY AND COMPUTATION 0 1 8 0 0 8 NA NA 1 1 1 NA NA NA NA NA NA NA NA
10.1021/es300447t ENG Reductions in Particulate and NOx Emissions by Diesel Engine Parameter Adjustments with HVO Fuel Happonen, M; Heikkila, J; Murtonen, T; Lehto, K; Sarjovaara, T; Larmi, M; Keskinen, J; Virtanen, A http://dx.doi.org/10.1021/es300447t http://www.altmetric.com/details.php?citation_id=1194445 2012 ENVIRON SCI TECHNOL ENVIRONMENTAL SCIENCE & TECHNOLOGY 2 1 1 0 0 1 NA NA 1 1 1 NA NA NA NA NA NA NA NA
10.1021/ic2021403 CHEM New Vanadium Selenites: Centrosymmetric Ca-2(VO2)(2)(SeO3)(3)(H2O)(2), Sr-2(VO2)(2)(SeO3)(3), and Ba(V2O5)(SeO3), and Noncentrosymmetric and Polar A(4)(VO2)(2)(SeO3)(4)(Se2O5) (A = Sr2+ or Pb2+) Yeon, J; Kim, SH; Nguyen, SD; Lee, H; Halasyamani, PS http://dx.doi.org/10.1021/ic2021403 http://www.altmetric.com/details.php?citation_id=482028 2012 INORG CHEM INORGANIC CHEMISTRY 8 1 6 0 0 6 NA NA 1 1 1 NA NA NA NA NA NA NA NA
library(shiny)
library(reshape2)
library(stringr)
library(ggvis)
# Few lines with double quotes inside fields terminated by quotes
# sed -i 's/""/%%/g' aalto_since2010.csv
aalto_all_m <- read.table(file = "aalto_since2010.csv",
header = TRUE,
sep = ",",
col.names = c("DOI", "School", "Title", "Authors", "URL",
"Altmetric.com_URL", "Year", "Journal_short", "Journal_long",
"WoS", "Altmetric", "Mendeley", "Connotea", "CiteULike",
"Readers_count", "GooglePlus", "Facebook", "Any_type_of_posts", "Twitter",
"Accounts", "Blog_posts", "Videos", "Delicious_bookmarks",
"Reddit", "Forums",
"StackExchange", "rh",
"Science_news_outlets"),
colClasses = c("character", "character", "character", "character", "character",
"character", "character", "character", "character",
"integer", "numeric", "integer", "integer", "integer",
"integer", "integer", "integer", "integer", "integer",
"integer", "integer", "integer", "integer",
"integer", "integer",
"integer", "integer",
"integer"),
stringsAsFactors = FALSE)
# Readers_count = Mendeley + CiteULike; rh = ?
aalto_all_m <- aalto_all_m[ ,c("DOI", "School", "Title", "Authors", "URL",
"Altmetric.com_URL", "Year", "Journal_short", "Journal_long",
"WoS", "Altmetric", "Mendeley", "Connotea", "CiteULike",
"GooglePlus", "Facebook", "Twitter",
"Accounts", "Blog_posts", "Videos", "Delicious_bookmarks",
"Reddit", "Forums",
"StackExchange", "rh",
"Science_news_outlets")]
names(aalto_all_m) <- c("DOI", "School", "Title", "Authors", "URL",
"AltmetricURL", "Year", "Journal short", "Journal",
"WoS", "Altmetric", "Mendeley", "Connotea", "CiteULike",
"GooglePlus", "Facebook", "Twitter",
"Accounts", "Blog posts", "Videos", "Delicious",
"Reddit", "Forums","StackExchange", "rh", "NewsOutlets")
# Altmetric.com_score value to ceiling
aalto_all_m$Altmetric <- as.integer(ceiling(aalto_all_m$Altmetric))
# In original data, we have duplicate DOIs if the article is co-authored by
# multiple Schools. Here, we deliberately delete that information, and
# the DOI is randomnly put under one of the Schools
aalto_all <- aalto_all_m[!duplicated(aalto_all_m$DOI),]
# Some Altmetric.com data is NA, some 0
aalto_all[is.na(aalto_all)] <- ""
# See remark on top
aalto_all$Title <- with(aalto_all, gsub("%%", "'", Title))
# For unknown reason, some columns need to be transformed twice to integer
columns <- c(which(colnames(aalto_all) == "GooglePlus"):ncol(aalto_all))
aalto_all[ ,columns] <- apply(aalto_all[ ,columns], 2, function(x) as.integer(as.character(x)))
# See ?toupper
simpleCap <- function(x) {
s <- strsplit(x, " ")[[1]]
paste(toupper(substring(s, 1,1)), substring(s, 2),
sep="", collapse=" ")
}
aalto_all$Journal <- sapply(aalto_all$Journal, tolower)
aalto_all$Journal <- sapply(aalto_all$Journal, function(x) simpleCap(x))
# Acronyms for plot labels and tooltips
aalto_all$Title5 <- with(aalto_all, paste(substring(Title,1,5), " (", Year, ")", sep=""))
aalto_all$Title20 <- with(aalto_all, paste(substring(Title,1,20), " (", Year, ")", sep=""))
#aalto_all$Authors5 <- with(aalto_all, paste(substring(Authors,1,5), " (", Year, ")", sep=""))
aalto_all$Journal5 <- with(aalto_all, paste(substring(Journal,1,5), " (", Year, ")", sep=""))
# Number of authors
aalto_all$NrOfAuthors <- with(aalto_all, as.integer(str_count(Authors, ";")+1))
# Keys for ggvis tooltips
aalto_all$keys <- seq(1, nrow(aalto_all))
metrics <- c("Altmetric", "WoS", "Mendeley", "Twitter", "Facebook", "GooglePlus", "CiteULike",
"Videos", "Reddit", "NewsOutlets", "NrOfAuthors")
dimensions <- c("Title", "Journal")
colsPlot <- c("Altmetric", "WoS", "Mendeley", "Twitter", "Facebook", "GooglePlus", "CiteULike",
"Videos", "Reddit", "NewsOutlets", "School", "Year", "Title5", "Journal5", "NrOfAuthors")
colsChart <- c("Altmetric", "WoS", "Mendeley", "Twitter", "Facebook", "GooglePlus", "CiteULike",
"Videos", "Reddit", "NewsOutlets", "id", "NrOfAuthors")
colsTable <- c("Journal", "Title", "AltmetricURL", "NrOfAuthors", "Altmetric",
"Authors", "Year", "WoS", "Mendeley", "School",
"Twitter", "Facebook", "GooglePlus", "CiteULike",
"Videos", "Reddit", "NewsOutlets")
shinyServer(function(input, output, session) {
output$items <- renderUI({
selectizeInput(
inputId = 'items',
label = 'Select max 4. Click to delete',
multiple = TRUE,
choices = aalto_all[ ,names(aalto_all) %in% input$dim],
options = list(maxItems = 4, placeholder = 'Start typing')
)
})
selected <- reactive({
if (is.null(input$items)) {
return(aalto_all)
}
df <- aalto_all[aalto_all[[input$dim]] %in% input$items, ]
df$keys <-seq(1, nrow(df))
df
})
selected %>%
ggvis(~WoS, ~NrOfAuthors, fill = ~School, key := ~keys) %>%
layer_points() %>%
add_tooltip(show_title) %>%
bind_shiny("gv")
show_title <- function(x=NULL) {
if(is.null(x)) return(NULL)
key <- x["keys"][[1]]
selected()$Title20[key]
}
})
shinyUI(fluidPage(
titlePanel('Some (alt)metric data since 2010'),
sidebarLayout(
sidebarPanel(
selectInput(
inputId = "dim",
label = "Dimension",
choices = dimensions,
selected = c("Title")),
uiOutput("items")
),
mainPanel(
tabsetPanel(
tabPanel("Plot with ggvis", ggvisOutput("gv"))
)
)
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment