#rstats adventures in the land of @rstudio shiny (apps)

Preamble
Colleagues and I had some sweet telemetry data, we did some simple models (& some relatively more complex ones too), we drew maps, and we wrote a paper. However, I thought it would be great to also provide stakeholders with the capacity to engage with the models, data, and maps. I published the data with a DOI, published the code at zenodo (& online at GitHub), and submitted paper to a journal. We elected not to pre-print because this particular field of animal ecology is not an easy place. My goal was to rapidly spin up some interactive capacity via two apps.

Adventures
Map app is simple but was really surprising once rendered. Very different and much more clear finding through interactivity. This was a fascinating adventure!
Model app exploring the distribution of data and the resource selection function application for this species confirmed what we concluded in the paper.

Workflow
Shiny app steps development flow is straightforward, and I like the logic!!
1. Use RStudio
2. Set up a shiny app account (free for up to 25hrs total use per month)
3. Set up a single r script with three elements
(i) ui
(ii) server
(iii) generate app (typically single line)
4. Click run app in RStudio to see it.
5. Test and play.
6. Publish (click publish button).

There is a bit more to it but not much more.

Rationale
A user interface makes it an app (haha), the server serves up the rstats or your work, and the final line generates app using shiny package. I could have an interactive html page published on GitHub and use plotly and leaflet etc, but I wanted to have the sliders and select input features more like a web app – because it is.

Main challenge to adventure was leaflet and reactive data
The primary challenge, adventure time style, was the reactive data calls and leaflet. If you have to produce an interactive map that can be updated with user input, you change your workflow a tiny bit.
a. The select input becomes an input$var that is in essence the name of vector you can use in your rstats code. So, this intuitive in conventional shiny app to me.
b. To take advantage of user input to render an updated map, I struggled a bit. You still use the input but want to filter your data to replot map. Novel elements include introducing a reactive function call to rewrite your dataframe in server chunk and then in leaflet first renderLeaflet map but them use an observe function to update the map with the reactive, i.e. user-defined, subset of the data. Simple in concept now that I get it, but it was still a bit tweaky to call specific elements from reactive data for mapping.

Summary
Apps from your work can illuminate patterns for others and for you.

Apps can provide a mechanism to interact with your models and see the best fits or outcomes in a more parallel, extemporary capacity

Apps are a gratifying mean to make statistics and data more accessible

Updates
Short-cut/parsimony coding: If you wrap your data script or wrangling into the renderPlot call, your data becomes reactive (without the formal reactive function).

The position of scripts is important – check this – numerous options where to read in data and this has consequences.

Also, consider modularizing your code.

Check out conditionalPanel function for customization across tabPanels. Tips in general here for shiny.

A checklist for choosing between #rstats packages

The paradox of choice can at times be a challenge. There are well over 10,000 packages on CRAN now (likely 16,000), and there have been suggestions on how to find what you need but not necessarily on how to choose between alternatives. Here is a brief checklist that I used to contrast two similar packages for doing meta-analyses in R (summarized in a preprint qualitatively).

criteriaitem
regularly maintained
recently updated
package maintainer on GitHub
manual available
vignettes available
used/published in similar projects
aligned workflow
semantics intuitive
contemporary grammar
functions that get the job done
arguments to support needs
visualization options (if needed)
dependencies reported/reasonable
connects to other packages

Implication

It is great to have different choices, and it is important to explore different alternatives because each can lead to potentially different adventures.

A vision statement describing goals for Ecology @ESAEcology #openscience

Many aspects of the journal Ecology are exceptional.  It is a society journal and that is important. The strength of research, depth of reporting, and scope of primary ecological research that informs and shapes fundamental theory has been profound.  None of these benefits need to change.  Nonetheless, research that supports the scientific process and engenders discovery can always evolve and must be fluent.  So must the process of scientific communication including publications through journals.  With collaborators and support from NCEAS and a large publishing company, I have participated in meta-science research examining needs and trends in the process of peer review for ecologists and evolutionary biologists, i.e. Behind the shroud: a survey of editors in ecology and evolution published in Frontiers in Ecology and the Environment or biases in peer review such as Systematic Variation in Reviewer Practice According to Country and Gender in the Field of Ecology and Evolution published in PLOS ONE.  In total, we have published 50 peer-reviewed publications describing a path forward for ecology and evolution in particular with respect to inclusivity, open science, and journal policy.  Ideally, we have identified at least three salient elements for journals relevant to authors, referees, and editors, and four pillars for a future for scholarly publishing more broadly.  The three elements for Ecology specifically would be speed, recognition, and more full and reproducible reporting.  The four pillars include an ecosystem of products, open access, open or better peer review, and recognition for participation in the process .

 

Goals to consider

  1. Rapid peer review with no more than 4 weeks total for first decision.
  2. A 50% editor-driven rejection rate of initial submissions.
  3. Two referees per submission if in agreement (little to no evidence more individuals are required).
  4. Double the 2017 impact factor to ~10 within 2 years and return to top 10 ranking in 160 of journals listed in field of ecology.
  5. Further diversify the contributions to address exploration, confirmation, replication, consolidation, & synthesis.
  6. Innovate content offering to encompass more elements of the scientific process including design, schemas, workflows, ideation tools, data models, ontologies, and challenges.
  7. Allow authors to report failure and bias in process and decision making for empirical contributions.
  8. Provide additional novel material from every publication as free content even when behind paywall.
  9. Develop a collaborative reward system for the editorial board that capitalizes on existing expertise and produces novel scientific content such as editorials, commentaries, and the reviews as outwardly facing products. Include and invite referees to participate in these ‘meta’ papers because reviews are a form of critical and valuable synthesis.
  10. Promote a vision of scientific synthesis in every publication in the Discussion section of reports. Request an effect size measure for reports to provide an anchor for future reuse (i.e. use the criteria proposed in ‘Will your paper be used in a meta‐analysis? Make the reach of your research broader and longer lasting’).
  11. Revise the data policy to require data deposition – at least in some form such as derived data – openly prior to final acceptance but not necessarily for initial submission.
  12. Request access to code and data for review process.
  13. Explore incentives for referees – this is a critical issue for many journals. Associate reviews with Publons or ORCID.
  14. Emulate the PeerJ model for badges and profiles for editors, authors, and
  15. Remove barriers for inclusivity of authors through double-blind review.
  16. Develop an affirmative action and equity statement for existing publications and submissions to promote diversity through elective declaration statements and policy changes.
  17. All editors must complete awareness training for implicit bias. Editors can also be considered for certification awarded by the ESA based on merit of reviewing such as volume, quality of reviews, and service. Recognition and social capital are important incentives.
  18. Develop an internship program for junior scientists to participate in the review and editorial process.
  19. Explore reproducibility through experimental design and workflow registration with the submission process.
  20. Remove cover letters as a requirement for submission.

Outcomes

I value our community and the social good that our collective research, publications, and scientific outcomes provide for society.  However, I am also confident that we can do more.  Journals and the peer review process can function to illuminate the scientific process and peer review including addressing issues associated with reproducibility in science and inclusivity.  Know better, do better.  It is time for scientific journals to evolve, and the journal Ecology can be a flagship for change that benefits humanity at large by informing evidence-based decision making and ecological literacy.

 

Ecological network flavors: many-to-many, few-to-many, and few-to-many spatially

Recent conference attendance inspired me to do a quick typology of networks that were presented in various talks. All were done in R using a few different packages.
All were interested in diversity patterns.
None were food webs.

Networks

many-to-many: many plant species and many pollinators for instance

few-to-many: mapping the associated set of pollinators to one flowering species

few-to-many: replicated mapping of diversity for one taxa to a single species of another either nested or spatially contrasted.

 

Network analyses are amazing. I need to learn more!

Can you also map interactions onto other interactions?