• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubybathyscaphegamewindowspythonphpguic翻訳omegattwitterframeworkbtronarduinovb.net計画中(planning stage)directxpreviewertestゲームエンジンdom

Commit MetaInfo

Revisiond1c6f572c457a3e4e46d4a977f354efe06868af5 (tree)
Time2020-01-14 06:50:36
AuthorLorenzo Isella <lorenzo.isella@gmai...>
CommiterLorenzo Isella

Log Message

I modified the code: now I can also download the data. The code must
be very sloppy, but it runs fast anyway.

Change Summary

Incremental Difference

diff -r b0d505c67844 -r d1c6f572c457 R-codes/app_fdi_viz.R
--- a/R-codes/app_fdi_viz.R Mon Jan 13 14:44:06 2020 +0100
+++ b/R-codes/app_fdi_viz.R Mon Jan 13 22:50:36 2020 +0100
@@ -64,17 +64,23 @@
6464 sidebarPanel(
6565 selectInput("reporterlabel",
6666 "Reporter:",
67- reporters ## , multiple=T
67+ reporters,
68+ selected="European Union (current composition)"
69+ ## , multiple=T
6870 ),
6971 selectInput("partnerlabel",
7072 "Partner:",
71- partners),
73+ partners,
74+ selected="Extra-EU28 (current composition)"),
7275
7376
7477
7578 # Button
76-downloadButton("downloadData", "Download the data"),
77- downloadButton("save", "Download the plot")
79+downloadButton("downloadData", "Download data selection"),
80+ downloadButton("save", "Download plot"),
81+ downloadButton("saveall", "Download full dataset")
82+
83+
7884
7985 ),
8086
@@ -98,7 +104,28 @@
98104
99105 server <- function(input, output) {
100106
101-
107+ dataset <- reactive({
108+ df_ini %>%
109+ group_by(year,Reporter, Partner) %>%
110+ summarise(IN_STOCKS=round(sum(IN_STOCKS, na.rm=T,0)),
111+ OUT_STOCKS=round(sum(OUT_STOCKS, na.rm=T,0)),
112+ IN_FLOWS=round(sum(IN_FLOWS, na.rm=T,0)),
113+ OUT_FLOWS=round(sum(OUT_FLOWS, na.rm=T,0))) %>%
114+ ungroup() %>%
115+ mutate(Entity="Special Entity plus Total",
116+ NACE="All NACE Actitivities") %>%
117+ select(year, Reporter, Partner, Entity, NACE, everything()) %>%
118+ arrange(desc(year)) %>%
119+ rename("Inward Stocks (Mio \u20ac)"="IN_STOCKS",
120+ "Outward Stocks (Mio \u20ac)"="OUT_STOCKS",
121+ "Inward Flows (Mio \u20ac)"="IN_FLOWS",
122+ "Outward Flows (Mio \u20ac)"="OUT_FLOWS"
123+ ) %>%
124+ arrange(Reporter, Partner)
125+
126+
127+ })
128+
102129
103130 filtered_data <- reactive({
104131
@@ -106,10 +133,10 @@
106133 Partner %in% input$partnerlabel) %>%
107134 arrange(desc(year)) %>%
108135 group_by(year,Reporter, Partner) %>%
109- summarise(IN_STOCKS=sum(IN_STOCKS, na.rm=T),
110- OUT_STOCKS=sum(OUT_STOCKS, na.rm=T),
111- IN_FLOWS=sum(IN_FLOWS, na.rm=T),
112- OUT_FLOWS=sum(OUT_FLOWS, na.rm=T)) %>%
136+ summarise(IN_STOCKS=round(sum(IN_STOCKS, na.rm=T,0)),
137+ OUT_STOCKS=round(sum(OUT_STOCKS, na.rm=T,0)),
138+ IN_FLOWS=round(sum(IN_FLOWS, na.rm=T,0)),
139+ OUT_FLOWS=round(sum(OUT_FLOWS, na.rm=T,0))) %>%
113140 ungroup() %>%
114141 mutate(Entity="Special Entity plus Total",
115142 NACE="All NACE Actitivities") %>%
@@ -120,6 +147,17 @@
120147 })
121148
122149
150+ filtered_data2 <- reactive({
151+ filtered_data( ) %>%
152+ rename("Inward Stocks (Mio \u20ac)"="IN_STOCKS",
153+ "Outward Stocks (Mio \u20ac)"="OUT_STOCKS",
154+ "Inward Flows (Mio \u20ac)"="IN_FLOWS",
155+ "Outward Flows (Mio \u20ac)"="OUT_FLOWS"
156+ )
157+
158+ })
159+
160+
123161
124162 tradeplot <- reactive({
125163 options( scipen = 16 )
@@ -182,7 +220,7 @@
182220
183221 )
184222
185- output$table <- renderTable(filtered_data())
223+ output$table <- renderTable(filtered_data2(), digits=0)
186224
187225
188226
@@ -198,11 +236,25 @@
198236
199237 },
200238 content = function(file) {
201- write.csv(filtered_data(), file, row.names = FALSE)
239+ write.csv(filtered_data2(), file, row.names = FALSE)
202240 }
203241 )
204242
205243
244+ # Downloadable csv of full dataset ----
245+ output$saveall <- downloadHandler(
246+ filename = function() {
247+ ## paste(input$dataset, ".csv", sep = "")
248+ paste("complete_dataset", ".csv", sep = "")
249+
250+ },
251+ content = function(file) {
252+ write.csv(dataset(), file, row.names = FALSE)
253+ }
254+ )
255+
256+
257+
206258
207259
208260 output$save <- downloadHandler(