Skip to main content Skip to navigation
CEREO September 2017

Indexing Tables From Plotly output

Submitted by our Working Group member Julia Piaskowski. We discussed this a bit in Trouble Shooting, but its relevant to anyone using Plotly. Thanks Julia! :

Plotly is an enormously handy set of interactive plotting function that have been developed for R, Python and D3.js. One very useful feature of plotly is “event_data” where users are able to click on or select parts of the plot for more information or to create new plots from the selected output. There’s several types of event_data, but I am focusing on “plotly_selected” where a user selects several points using a lasso or box selection tool.

I am using plotly in R/Shiny to create an interactive plot. The idea seemed simple: generate a bivariate scatterplot colored by a factor in the data set. Users should be able to select a region of interest, and the full data from those observations will be presented in a table. However, the indexing was not working using the usual mydata[rows,columns] method – it worked for some observations, but not others.

The problem was that the data were being unstacked by the grouping variable used to color the plot, essentially creating a separate a rowXcolumn object for each level of the grouping variable.

The solution was slightly complicated, requiring both subsetting the object AND the plotly event_data. A small example is shown below. A bigger demo is at: https://jpiaskowski.shinyapps.io/cherry_gebv_xplorr/

library(shiny)
library(plotly)

# Make data
set.seed(123)
mydata<-data.frame(Name = replicate(10,paste(sample(LETTERS,3),collapse = “”)),
a = 1:10,b = sample(1:100,10),c = rep(c(“up”,”down”),5),
d = paste0(“secret_data”,1:10))

# Generate the Display (ultra simple in this example)

ui <- fluidPage(
fluidRow(
column(6, tags$h3(“Basic Plot”), plotlyOutput(“Plot1”, height = “300px”)) ,
column(6, tags$h3(“Selected Output”), tableOutput(“clickTable”))
))

# server info
server <- function(input, output){

output$Plot1 %>%
layout(
dragmode = “select”)
})

output$clickTable <-renderTable({

event.data.select <- event_data(“plotly_selected”, source = “subset”)

if(is.null(event.data.select) == T) return(“Choose individuals by selecting a region in the scatterplot”) else {

# Get index from each group
# This is the where indexing was failing previously. The scripts must reference both the group variable (called the “curveNumber” AND the observation (the “pointNumber”). Not to be outdone by something more confusing, plotly is going against R convention and starting their indexing at zero – hence the use of “0” for the “up” group, and why a value of 1 is added to each “pointNumber”.

up.group <- subset(mydata, c == “up”)[subset(event.data.select, curveNumber == 0)$pointNumber + 1,]
down.group <- subset(mydata, c == “down”)[subset(event.data.select, curveNumber == 1)$pointNumber + 1,]

# Combine and make table
table.subset <- rbind(up.group,down.group)
}

})

shinyApp(ui = ui, server = server)

Scientific Assistant Position: Washington State University, Stable Isotope Core Laboratory

Assist the laboratory manager for the WSU stable isotope core facility. Help develop innovative approaches and methodologies in stable isotope analyses. Interact with the Laboratory Information Management database. Maintain facility web page. Ensure satisfactory operation of specialized research equipment to serve needs of the facility. Train personnel in preparation of samples and equipment usage. Supervise student workers. Maintain lab inventory and make lab orders. Implement laboratory QA/QC and safety protocols. In addition, the incumbent performs routine maintenance on specialized research equipment; analyzes and interprets initial equipment output; and schedules lab resources to process tasks at hand. This position supervises and delegates responsibilities to student workers in the laboratory.
To view the full description and apply online visit: https://www.wsujobs.com/postings/33810

 

Word Clouds

Today Stephanie Labou spoke about text mining and word clouds. Our script today used the “tm” and “wordcloud” packages.

Some questions were asked at our session, primarily 1) can you mine PDFs? The answer is yes! You can! You can find more information about reading in text from PDFs here and here and here is the online book about text mining in R (including sentiment analysis and n-grams).

Here is some example text to run with the script: data_skills_ms , sourced from Stephanie Labou’s paper

Here is the script: WordCloudScript!

Intro to R

This week was our introduction to R lecture. This lecture was a brief overview of what R is and how to use it, with the goal of making the newer R users in our community literate in R syntax. For this session users needed to have downloaded both R and R Studio.

First we discussed what R is, along with some great resources that people can use to learn R. The first resource comes from the Software Carpentry team: https://swcarpentry.github.io/r-novice-gapminder/. The second is from one of our fellow R group members, Rachel Olsson, and is an introduction for new users designed for one of her labs, but applicable here. Make sure to download both the Lab1 Walkthrough and the Floral_diversity dataset.

The R script for our session (in .txt), along with the notes we added to it in class: IntroRScript

2017 Outreach Program Request for Proposals (RFP) for NWS/Office of Water Prediction/National Water Center (NWC) Cooperative and Partners Projects:

• NWC Cooperative Projects: COMET anticipates awarding two-four competitively reviewed, 1-2-year projects, each with a budget maximum of $40,000. The deadline for submission of a preliminary synopsis is October 2, 2017, with the final proposal due December 15, 2017. For more information, please see NWC Cooperative Projects RFP and the guidelines for NWC Cooperative Project proposal submissions.
• NWC Partners Projects: COMET is currently accepting 1-year NWC Partners proposals (budgets limited to $15,000). Proposals will be reviewed as received, and approved submissions will be funded until program resources are expended. For more information, please see NWC RFP Details. It is anticipated that up to six projects will be awarded. For details on these projects, see NWC Partners Proposals.

WSU Study on Science Literacy- Participants Needed

Science literacy is an important outcome for students. One aspect of this is the development of scientific knowledge or the nature of science. Please consider participating in a study by Larry Collins that examines expert vs. novice views of the development of scientific knowledge. Participation will take approximately 10-15 minutes. You’ll be asked to complete a sorting task that could be adapted for assessing science content in undergraduate courses. Please contact Larry Collins (larry.collins@wsu.edu) for more information.