owned this note
owned this note
Published
Linked with GitHub
**NBIS Workshop**
# Plotting in R Sep-2021
Welcome to the *Workshop on plotting in R* workshop organised by National Bioinformatics Infrastructure, Sweden.
This document is a life record of what we are doing and learning during the workshop. As either a student or a teacher, you are encouraged to write your comments, questions and feedback.

## Useful resources
- **Course website**: https://nbisweden.github.io/workshop-plotting-in-r/2109/
- **HackMD (this document):** https://hackmd.io/TgD7dpvRTDyjXUnZ5Iggvg?both
- **Zoom link:** https://uu-se.zoom.us/j/69943682163 (passcode has been sent to you).
:::info
**Note!** Zoom link is active from 09:00-17:00 (GMT+1) every day from Wed, 08 to Fri, 10 Sep 2021.
:::
## Introduction
Here, we write a few words about ourselves to get to know each other a bit better.
#### Teachers
* **Lokeshwaran Manoharan** - I am the course leader for this workshop. I work as a Bioinformatics expert at NBIS in the medical faculty node of Lund University. My research interest lies very much in the genomics of non-model organisms and microbes in particular.
* **Markus Ringnér** - I am one of the teachers for this workshop. I work in the NBIS long term support team and have my office at the Biology Department, Lund University. I have a background in cancer genomics.
* **Louella Vasquez** - I am one of the teachers for this workshop. I am based in Lund under the medical faculty. My background is in epigenetics and genetic association QTL analysis. I love cats.
#### Students
* **Kajsa Brolin** - I'm a 3rd year PhD student at the Medical faculty, Lund University. Working with genetics and epidemiology in Parkinson's disease etiology.
* **Javier Florenza** - I am a late stage PhD student at Uppsala University, Dept. of Ecology and Genetics, working in the development of a handful of techniques that target unicellular, mixotrophic algae at individual level.
* **Magdalena Ksiezarek** - Hi all, I am a last year PhD student in Microbiology at Faculty of Pharmacy, University of Porto, Portugal. I work on urogenital microbiome and by now I analyze mostly compositional and genomics data, mostly in R. Looking forward to sharpen my skills in plotting!
* **Nina Hollfelder** - I am a postdoc in Uppsala University working in human population genomics. My focus is on African populations, specifically hunter-gatherers and fringe populations. I am trying to decipher their genetic history using both modern genomes as well as ancient DNA. I use R regularly, plotting with ggplot, but am fairly new to the tidyverse. I am really looking forward to learn about R shiny.
* **Sara Mravinacova** - Hi all! I am Sara and I am a second year PhD student at KTH, Stockholm, working in the proteomics field. My main focus is neurodegenerative diseases such as Alzheimer's disease or frontototemporal dementia but I also partially work on some Covid19 projects. I use R on a regular basis and in majority work with tidyverse, but I have no experience with R Shiny and wold also like to learn how to do PCA plots and heatmaps in a more comfortable way!
* **Viktor Sincic** - Hi! I'm a 2nd year PhD student at LTH, Dept. of Immunotechnology. My research is focused on understanding immune cells in cancer and why they fail to eliminate cancer cells. I'm mostly working with single cell transcriptomics.
* **Srivathsa Magadi** - Hello everyone, I am postdoc at Walker Jackson's group @ Linkoping, the lab focuses on studying selective vulnerability in several neurodegenerative diseases including AD, PD, HD and prion diseases. We use SLAMseq and other RNA sequencing. New to using R and for most of my sequencing data analysis I am stuck at .txt files, except eyeballing at it , did not do much. I hope with this course I would be able to visualize data and explain it to others.
* **Sascha Krakovka** - Hi! I am Sascha, a late stage PhD student at Uppsala University, Dept. of Cell and Molecular Biology and Uppsala Antibiotic Resistance Center. I am working on resistance towards metronidazole in *Giardia intestinalis* an intestinal parasite using transcriptomics and proteomics data, since no major genetic changes seem to occur. As part of this I use R on a daily basis. I am hoping to improve my plots and especially learn more about R shiny apps.
* **Christer Sylvén** - Hello, I am Christer Sylvén, retired cardiologist. Since a few years working with SciLifeLab on the development of the human fetal heart and the mouse heart exposed at the NASA space station using scRNA-seq and spatial transcriptomics.
* **Johanna Stedt** - Hi! I'm a PhD student at the Unit of Aquatic Ecology, Department of Biology, at Lund University. I'm studying the foraging ecology of harbour porpoises and often work with large time series data sets. I have previous experience in R, but hope this course will help me organize and present my data in the best possible way.
* **Jamil Yousef** - Hey! I am a Research Engineer working at the division of Affinity Proteomics in KTH, Stockholm. The research I am involved in focuses on neurodegenerative disorders such as ALS and Alzheimer´s disease, but lately I have been involved in several Covid19 projects. I have experience in R before, but are fairly new to tidyverse and hope to learn about R shiny.
* **Lavanya Lokhande** - Hi, I am a PhD student from the department of Immunotechnology, Lund University. I work with proteomics and spatial omics lymphoma (GeoMX digital spatial profiler) datasets for biomarker discovery and exploring the immune microenviroment. I enjoy coding and know R and python. I hope I can improve my skills further and I am especially really excited to learn about Rshiny!
* **Franzi(ska) Hildebrandt** - Hi, my name is Franzi and I am a 3rd year PhD student at the Department of Molecular Bioscienecs at Stockholum University. I work with single cell and spatial transcriptomics data sets in the context of parasitology, more specifically in the context of malaria infection and transmission. I have experience in R and love the possibilities plotting and particularly ggplot offer and am very excited to learn more about the fundamentals in this course. Lovely to meet you all!
* **Alrik Schörling** - Hello everybody! I’m a first-year PhD student studying the use of cell therapy to treat neurodegenerative disorders in the Agnete Kirkeby group in Lund. Excited for this course!
* **Sophie Tronnet** - Hello, I am a Posdoc at MIMS, Umeå, Sweden. I am studying the response to eATP in intestinal bacteria. I have a bit of experience with R, and globally the more I learn programming, the more I love it!
* **Alejandro Rodríguez Gijón** - Hola! I'm a PhD Student at Stockholm University and SciLifeLab. I work on microbial ecology: I study the relevance of genome size in bacteria and archaea to adapt to different environments and how different ecological variables can affect this. Lovely to meet you!
* **Karin Ytterberg** - Hello everyone! Just started my PhD at University of Gothenburg where I am going to investigate the familial aggregation of gestational duration and preterm delivery. Looking forward to improving my plotting skills.
* **Jan Karlsen** - Hi! I am a PhD student at KTH and I study gene expression and metabolic regulation in cyanobacteria using systems biology tools like mRNA-seq, ribo-seq and protein mass spectrometry. Especially looking forward to learn how to make interactive web apps in R-shiny.
## Some important links
* [**Markdown syntax**](https://guides.github.com/pdfs/markdown-cheatsheet-online.pdf)
* [**ggplot2 cheatsheet**](https://www.maths.usyd.edu.au/u/UG/SM/STAT3022/r/current/Misc/data-visualization-2.1.pdf)
* [**A really good and comprehensive R heatmap package**](https://jokergoo.github.io/ComplexHeatmap-reference/book/index.html) - Complex Heatmap
* [**R graph Gallery**](https://www.r-graph-gallery.com/)
* [**RShiny cheatsheet**](https://shiny.rstudio.com/images/shiny-cheatsheet.pdf)
## Wednesday - Day 1
### Questions & Issues
- [x] **What does the negative sign in `-Gene` mean as in `gather(Sample_ID, Raw, -Gene)` ?**
>For the function `gather`, it will ignore column `Gene` when it gathers all columns into new columns `Sample_ID`, `Raw`. `Gene` column here is kept as it is and will not be pulled into the `Sample_ID` column!
```
> head(gc_raw)
Gene Sample_1 Sample_2 Sample_3 Sample_4 Sample_5 Sample_6 Sample_7 Sample_8 Sample_9 Sample_10 Sample_11 Sample_12
1 ENSG00000000003 321 303 204 492 455 359 376 523 450 950 760 1436
2 ENSG00000000005 0 0 0 0 0 0 0 0 0 0 0 0
3 ENSG00000000419 696 660 472 951 963 689 706 1041 796 1036 789 1413
4 ENSG00000000457 59 54 44 109 73 66 60 125 74 108 115 174
5 ENSG00000000460 399 405 236 445 454 374 316 505 398 141 168 259
6 ENSG00000000938 0 0 0 0 0 1 0 0 0 1 0 0
gene_counts_all <-
+ gc_raw %>% gather(Sample_ID, Raw, -Gene)
head(gene_counts_all)
Gene Sample_ID Raw
1 ENSG00000000003 Sample_1 321
2 ENSG00000000005 Sample_1 0
3 ENSG00000000419 Sample_1 696
4 ENSG00000000457 Sample_1 59
5 ENSG00000000460 Sample_1 399
6 ENSG00000000938 Sample_1 0
```
>If you keep the column `Gene`, that is run gather without `-Gene`, then the results are as follows. You get a long table with `Gene`as one of the variables.
```
> gc_long_with_gene = gc_raw %>% gather(Sample_ID, Raw)
> head(gc_long_with_gene)
Sample_ID Raw
1 Gene ENSG00000000003
2 Gene ENSG00000000005
3 Gene ENSG00000000419
4 Gene ENSG00000000457
5 Gene ENSG00000000460
6 Gene ENSG00000000938
> tail(gc_long_with_gene)
Sample_ID Raw
774444 Sample_12 0
774445 Sample_12 0
774446 Sample_12 0
774447 Sample_12 0
774448 Sample_12 0
774449 Sample_12 0
```
- [x] **What does the parameter `by = 0` mean in `merged_data_wide <- merge(md, t(gc), by = 0)` ?**
> Here, the `merge` function will combine two data frames by their rownames, i.e., by invoking the parameter `by = 0`. Note that in the exercise, we have explicitly assigned the rownames of the dataframe by executing command `rownames(md) <- md$Sample_ID`.
- [x] **Which of these two would be preferred, and why?** `cbind(md,t(gc))` **or** `merge(md, t(gc), by=0)`**?**
> For the purpose of our exercise where we combine gene expression count data `t(gc)` with a metadata containing sample information `md`, we should use `merge()`. By using `merge()`, we can impose that the two dataframes will be merged by matching same `Sample_ID` as specified by the parameter `by` in `merge(..,..,by= )`. Note that when using `merge()`, the two dataframes do not need to have the same row order to begin with. Also, the two dataframes can have different row dimension.
> The function `cbind` will simply concatenate the columns of the two dataframes, nothing more. It also requires the two dataframes to have same row dimension.
- [x] **In the explanation of the lab ggplot: Part I, we add a categorical column `cat` with the entries `C1 or C2`. I was curious whether this is added as a character or factor based what we learned in the previous lecture. Turns out it is a characters. When would it be beneficial to convert a column of characters into a column with factors ( For instance, if I am not mistaken previous R versions automatically added factors instead of characters when reading some data, which sometimes was quite annoying) ?**
> This is absolutely true! it used to be the case that all the string columns are read in as factors and you had to spcify `stringsAsFactors = FALSE`. The advantage of having a factor is when you are calculating statistics! To calculate statistics, R has to know that this particular column/variable has two factors like say `control` and `treatment`, then it can calculate `mean`, `SD` and so on just with the `summary()` function. For ggplot itself, this might not be so crucial!
- [x] **what is the difference between adding `mapping=` and not adding `mapping=` in `aes()`?**
> So, as mentioned in the lecture, if you want to pull the aesthetics from the data like let's say you want the `color` in the plot from `iris` data to be according to their `Species`, then you add `aes(color = Species)`. if you just want to use a single color for all the data then you do something like `color=#808B96`. Here, this is not mapping because you are not getting(or mapping) the color parameter from the data!
- [x] **When I am plotting a barplot using ggplot I understand that I can use `geom_col()` as suggested in the markdown. However, when plotting my own graphs using ggplot I often use `geom_bar`. In doing so I have to speicify `stat = "identity"` in the function. I mainly took over this codes from other colleagues in my lab and never questioned it. Now I however wonder why I have to specify it and what exactly it means. Maybe you can ecplain the differnces between `geom_col()` and `geom_bar()` and why I have to specify `stat` ?**
> You can view `geom_bar()` as having more functionality than `geom_col()`. If one has data that are paired as in group/x-value and a count/y-value for each group/x-value, one can generate a barplot for this data using `geom_col()`. `geom_bar()`on the other hand does not expect a y-value (count in this case), instead it calculates the y-value from the data (from the x-values). For example with `stat="count"` `geom_bar()`sums up the number of times each group/x-value appears and makes a barplot of that, but `geom_bar()` can also aggregate the data in more customizable ways. If one already has the number of times each group appears then `geom_col()` is a more simple notation to generate columns in a barplot, but `geom_bar()`provides this same functionality with `stat="identity` since it then overides the aggregation that `geom_bar()`can do in different ways.
- [x] **Can `RColorBrewer` only be used for discrete colors?**
> `RColorBrewer`is for a limited number of colours. So even if you can technically make a continous colour scale there are practical limitations. For continous colour scales see an example [here](https://sites.google.com/site/seascapemodelling/home/r-code/customising-plots/continous-colour-brewer-palettes)
- [x] **Can `facet_wrap` specify the size of the subplots? For example, a bigger plot for one group and two equally small plots for the other two groups?**
> I don't think it can, but the patchwork package makes this simple (check https://ggplot2-book.org/arranging-plots.html) -Nina
- [x] **Can you resize your plots, especially for viewing in R markdown? In particular with `facet_wrap` where if you have too many subplots and the axis's then get constricted.**
> Nina is right! You could find some cumbersome wrap around solutions using `facet_wrap` to your question from googling :). A good solution would probably be the functionalities that we will be learning on Thursday session about arranging and combining plots, please see [here](https://nbisweden.github.io/workshop-plotting-in-r/2109/lab_gg4.html#11_plot_grid).
- [x] **In the ggplot part III exercise, you suggest to use geom_line(aes(group=1), stat = "identity"), can you please explain what the =1 and stat = "identity" actually mean? I would do group = Replicate instead and did not specify stat at all which gives exactly the same plot and makes more sense to me. Is there any advantage maybe in another example where it would be important to do it in the way you suggest?**
> The parameter `stat = "idenity"` is unnecessary in this example. Nevertheless, it just means to accept the data as is without any tranformation eg y values become the frequency of x values.
> The first lines of the command `gc_long %>% group_by(Time, Replicate)` create a tibble whereby the data groups are defined by `Time` and `Replicate`. The first group `Time` is inherited when ggplot is invoked. To override this, you have to explicitly define your choice of group such as by `geom_line(aes(group=1), size = 2)`. Here `group=1` means to take the "natural grouping" when ggplot was set up, ie by Replicate as seen here `ggplot(aes(x=Time, y=mean, color = Replicate))`.
Alternatively, you can also clearly state `group=Replicate`.
```
gc_long %>%
group_by(Time, Replicate) %>%
summarise(mean=mean(log10(count +1)),se=se(log10(count +1))) %>%
ggplot(aes(x=Time, y=mean, color = Replicate)) +
facet_wrap(~Replicate) +
geom_line(aes(group=Replicate), size = 2)
```
### Bugs
- [x] Change the name of the metadata file: `metadata_raw.csv` is confusing!
### Feedback
- [x] Lectures as PDF.
## Thursday - Day 2
### Questions & Issues
- [x] **When we are drawing a canvas in ggdraw what is the unit of the dimensions? I am assuming pixels? Would it be possible to define the unit in mm or cm as this usually is the unit I am thinking in when designing figures for publications?**
> In ggdraw canvas, the unit is the ggplot plotting unit in cartesian coordinate. You can actually change the setting of this canvas in parameters xlim, ylim.
`ggdraw(plot = NULL, xlim = c(0, 1), ylim = c(0, 1), clip = "off")`. In this way you can change the aspect ratio of your plot.
When you save your ggdraw plot as an image [via `ggsave()`, `pdf()`,`png()`] then you specify the image units in terms of inches, cm, dpi etc.
- [x] **When I am creating figures in R directly, is there a way to make sure that the font-size for individual plots are as I need them, when combining plots? Many journals require a minimum text size in figures and sometime it is very difficult to know if these requirements are met when I am trying to make a plot directlt in R instead of using a an illustration program to generate the figures.**
> In short. No, you have to save it and see if it actually looks good! You can actually set these font sizes for the different places of your plot using the `theme()` function as I showed it in my lecture from Day 1. you can set these parameters for the different options using `element_text()`
- [x] **Do you think cowplot/ggpubr are better/easier to use than patchwork?**
> We haven't used patchwork, but from what we heard it works well as well. It is probably better to use one or the other and may preferable to get used to one and learn the specifics/details of it to be able to generate your plot arrangements in a convenient fashion (and then switch if one of them cannot handle some type of plots that you need).
- [x] **When I use ggpubr to make a plot with a shared legend, can I specify which legend should be used? For example if I prefer the style of the second legend or does it always take the legend of the first plot?**
> In all `geom_` functions there is an option `show.legend` to turn on or off! Maybe this is not what you mean! You can try this and see if it works.
--> it is actually not what I mean :) - I meant whether I can specify if it should show the legend of the first or the second plot as the shared legend (in the case of having two plots).
> --> Okay, I am guessing turning the legend off in plot makes it look like it doesn't have a legend and then the `common.legend` doesn't work anymore! I will get back to this after a bit of googleing ;)
--> great, thank you so much! I can also elaborate a little further on this question in the discussion on zoom! :)
> --> This is one way to do it and probably not the best way to do it ;) You can use `get_legend` function and extract the legend you want and then you can arrange the legend in the final plot! this means you turn off the legends in both/all the plots!
- [x] **Looking at `vst_pca$x` in the PCA lab, I was wondering what the values in for each PC and sample describe. Maybe I missed it in the explanation**
> This is a very good question because the different PCA functions build up the PCA data objects in different variable names and their structures are usually different! It is important to check how these objects are structured. Specifically in short `vst_pca$x` contains the projections of the samples on the different principal components.
- [x] **I also noticed that in the code chunk where the different columns are added to the `vst_pca_all` object, the columns are added as factors as opposed to character columns, is there a specific reason for that?**
> --> Are you referring to this line as an example ?
`vst_pca_all$Sample_Name <- factor(vst_pca_all$Sample_Name, levels = c("t0_A","t0_B","t0_C","t2_A","t2_B","t2_C","t6_A","t6_B","t6_C","t24_A","t24_B","t24_C"))`
--> yes!
> --> We use them as factors, so that we can keep the order of time points here! Otherwise they get sorted alphabetically! I was wrong yesterday when I said for ggplot factors dont mean anything! It is useful to keep the order of the variables :) if you dont use factors and specify the levels in the order as mentioned above, `t24` will appear before `t6`, because in computer language '24' is alphabetically less than '6'.
- [x] **`envfit` package that was mentioned in one of the notes, how does it work to visualize the environmental factors and their correlations on a PCA/MDS**
> Each sample/experiment (S) has say measurements for the expression levels of a lot of genes, and this is what the PCA is performed upon. Each sample will have a projection onto the princial components such that a sample S1 can be expressed as S1 = kPC1 + lPC2 + mPC3 ... just as for the genes, and with a set of such equations for all samples they can be inverted to PC1 = pS1 + qS2 + rS3 + ... . Environmental factors (or other measurements independent of the expression levels) have a value for each sample and one can calculate the correlation/distance between the environmental factor and the PC expressed as vectors along samples. In this way the environmental factor can be expressed as a vector with the PCs as base, just as the genes in the lecture. And one can plot the direction of the environmental factors in the same fashion as the genes in our example for the PCA biplot.
- [x] **`envfit` example to put it somewhere**
> First calculating the correlation of the environmental variables to the ordination and how the object `nut_envfit` would look like:
```
nut_envfit <- envfit(BC_ord$vectors, Nut_inter_md, na.rm = TRUE)
nut_envfit$vectors
## Axis.1 Axis.2 r2 Pr(>r)
## energy_kJ 0.99340 0.11470 0.0210 0.210
## energy_kcal 0.99355 0.11343 0.0210 0.211
## protein -0.92562 0.37845 0.0124 0.402
## protein_E% -0.99220 0.12462 0.0660 0.009 **
## tot_fat 0.91690 0.39912 0.0117 0.416
## tot_fat_E% 0.24816 0.96872 0.0087 0.534
## sat_fat 0.99991 -0.01326 0.0223 0.188
```
> Then you can extract this information the `nut_envfit` using the `scores` function. Then here I will also just choose the signifcant ones! Then use that as the second data to plot on the ordination plot!
```
nut_env.df<-as.data.frame(scores(nut_envfit, display = "vectors"))
nut_env_sig.df <- nut_env.df[nut_envfit$vectors$pvals < 0.05,]
nut_env_sig.df$variable <- row.names(nut_env_sig.df)
ggplot() +
geom_point(data = BC_ord$vectors[,c(1,2)], aes(Axis.1, Axis.2, color = Time), size = 5) +
geom_segment(data=nut_env_sig.df,aes(x=0,xend=Axis.1,y=0,yend=Axis.2),
arrow = arrow(length = unit(0.5, "cm")),colour="black",inherit_aes=FALSE) + geom_text(data=nut_env_sig.df,aes(x=Axis.1,y=Axis.2,label=variable),size=5) +
```
- [x] **How to make a plot with dual Y axis? (In my case I have barplots in the left axis and line in the right axis)**
> Do you mean something along the following lines?
```
ggplot(data, aes(x=myX)) +
geom_bar(aes(y=myfirstY), ...) +
geom_line(aes(y=mysecondY), ...)
```
> And then have a scale for myfirstY on the left hand side and a scale for mysecondY on the right hand side?
> If that is the case then one can do it using `sec.axis()`. However `ggplot` sets up the plot with a single scale for the y-axis so one has to transform the second variable if its data range is different. A common way is to tranform the second data set and then inverse transform its scale to reflect the transform as follows:
```
# Value used to transform the data
scale_factor <- XXXXXXXX # E.g. 10
ggplot(data, aes(x=myX)) +
geom_bar(aes(y=myfirstY), ...) +
geom_line(aes(y=mysecondY/scale_factor), ...) + # Divide by scale_factor to get the mysecondY into the same numerical range as myfirstY
scale_y_continuous(
# Features of the first axis
name = "First Axis",
# Add a second axis and specify its features
sec.axis = sec_axis(~.*scale_factor, name="Second Axis") # Multiply with scale_factor to get the correct values on the scale given that we plotted mysecondY/scale_factor.
)
```
> So since `ggplot` sets up the the plot with a single set of coordinates you need to manually adjust and play around with `scale_factor`to get the relationsship between the two different scales in a way that looks appealing. For more details, please see [here](https://www.r-graph-gallery.com/line-chart-dual-Y-axis-ggplot2.html).
### Bugs
- [x] **older versions of `ggtree` sometimes get installed and they create problems**
```
Error in DataMask$new(.data, caller_env) : argument "caller_env" is missing, with no default
```
Louella did not see this error nor have problems with ggtree. R version 4.0.3. ggtree version is
```
packageVersion("ggtree")
[1] ‘2.4.1’
```
You can follow this issue here:
https://github.com/YuLab-SMU/ggtree/issues/399
Copied from above link:
```
Please also update tidytree by remotes::install_github("YuLab-SMU/tidytree") .
This is beacuse the mutate.tbl_tree in tidytree was not updated in old version.
I also rolled back dplyr from 1.0.6 to 1.0.5 as per his instructions.
Not sure whether the tidytree change would have been suffcient,,
and I'm not brave enough to try.
```
### Feedback
- [ ] Maybe we should include patchwork in the next version of the course.
- [ ] Way to control exact font sizes in image saved through ggsave?
- [ ] More extensive heatmaps (perhaps other packages than pheatmap).
## Friday - Day 3
### Questions & Issues
- [x] Can I still add RShiny code chunks into my Rmd file that contains Day 1 and 2 code chunks? If yes, how do I make sure the RShiny code chunks execute the html output ?
> The way I would test for this lab is to create a file called `app.R` and put the `ui()` and the `server()` codes in there along with `shinyApp(ui=ui,server=server)`. Then, this file will automatically be recognized as an app! Also to do it more correctly, I would create a specific directory and put all the files related to an app that you are developing in that directory including your `app.R` file!
> If you just want to run a specific Rshiny code chunk to see a quick output, the lazy way is just to highlight the code chunk and click `Run` :)
- [x] **When I want to provide my own input data in an interactive shiny app and use the `fileInput` widget, to let the user aka me upload the data, will I have to call `getdata` to be able to generate the html output?**
> So, `getdata()` function you write as a reactive function to `get()` the data from within R packages. So, no you can read in the file directly from the `input$` variable. I have an example below:
```
ui <- fluidPage(
.....
fileInput("file1", "Choose CSV File", accept = ".csv"),
checkboxInput("header", "Header", TRUE)
,
mainPanel(
.....
)
server <- function(input, output) {
.....
file <- input$file1
own_data <- read.csv(file$datapath, header = input$header)
.....
}
```
- [x] **When I am running ` randomVals <- eventReactive(input$click, {
rnorm(input$num)
})
output$hist <- renderPlot({
hist(randomVals(), title = input$title)
})` the shiny app does not update the title upon clicking**
it should be` main` instead of` title` here. If you update the code, it works.
> Yes, you are absolutely right. Thanks! Someone also pointed out the same bug under Bugs below.
- [x] **Can I save my shiny app for any webserver or does it have to be specific ones that execute R etc**
> It is not a matter of the webserver actually! it is important that your server where you are running the app has all the packages necessary installed. If this answered your question?
So then it has to be a server within the scientific community :)
- [x] **When we subset our Covid data to only include the countries we are interested in using
`subset_covdata <- cov_data %>% #Here we subset the covid data in the app
filter(location %in% input$countries) %>%
filter(date >= input$in_duration_date_start) %>%
filter(date <= input$in_duration_date_end)`
we are doing so within the server function, this could also be done outside of the function/beforehand, correct?**
> This needs to be done within the `server` function as the reactive value `subset_covdata` depends on several input variables `input$` taken from the `ui` function.
### Bugs
- [x] part2 section 3 the histogram calls for `title =` where it should call for `main = ` which generates an error and the title of the plot does not update due to this.
- [x] Part 3 section 4 needs `cov_data$date <- as.Date(cov_data$date)
` so it will compile correctly
- [x] Part 3 section 5 `read.table("shiny_app_data.csv ..."` should be `read.table("data/shiny_app_data.csv ..."`
- [x] in 5.3.2 as previously `read.table("shiny_app_data.csv ..."` should be `read.table("data/shiny_app_data.csv ..."`
### Feedback
## Feedback during feedback session
- [ ] More specific description of the course in the advert webpage regarding R-expertise level to not scare away R-beginners.
- [ ] Day 1 lab session about R and data wrangling is too long. The rest of Day 1 sessions could benefit with more time.
- [ ] Day 2: would be helpful to state at the very beginning in the Exercise webpage the list of packages that need installing and instruction to register a Google Cloud account.
- [ ] Day 2: Section of heatmaps could benefit with more explanation.
- [ ] Day 3: Would be helpful to have an "exercise" section for the students rather than just "copy-paste" the codes from the exercise notes.