-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathui.R
More file actions
93 lines (79 loc) · 3.39 KB
/
Copy pathui.R
File metadata and controls
93 lines (79 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
library(shinycssloaders)
# Get vector of reporter country names.
reporters <- comtradr:::get_country_db() %>%
filter(reporter) %>%
.[["country_name"]] %>%
.[. != "All"]
# Get vector of partner country names.
partners <- comtradr:::get_country_db() %>%
filter(partner) %>%
.[["country_name"]] %>%
.[. != "All"]
# Get vector of commodities.
commodities <- comtradr:::get_commodity_db()$commodity
# Create UI.
shinyUI(fluidPage(
# Application title.
tags$div(
tags$h1("UN Comtrade Data Viz"),
tags$h3("Tool for plotting inter-country shipping data from the United Nations Comtrade DB")
),
br(),
# Sidebar with a a number of fields for user input.
sidebarLayout(
sidebarPanel(
HTML("Provide input for Reporting Country, Partner Countries,
Commodities, Trade Direction, and y-axis metric."),
br(),
HTML("Click the 'Plot' button to update the plot."),
br(),
br(),
selectInput("reporter",
label = "Reporting Country:",
selected = "China",
choices = reporters,
multiple = TRUE),
selectInput("partner",
label = "Partner Countries:",
selected = c("USA", "Mexico", "Rep. of Korea"),
choices = partners,
multiple = TRUE),
selectInput("commod",
label = "HS Code / Commodities:",
selected = "TOTAL - Total of all HS commodities",
choices = commodities,
multiple = TRUE),
checkboxGroupInput("trade_direction",
label = "Trade Direction for Reporting Country:",
choices = c("Imports" = "Imports",
"Exports" = "Exports",
"Re-Imports" = "Re-Imports",
"Re-Exports" = "Re-Exports",
"All" = "All"),
selected = "Exports"),
radioButtons("value_vs_kg",
label = paste("Plot 'value of shipments' or 'weight of shipments' along y-axis",
"(Many Comtrade datasets do NOT include data on shipment weight):", sep = "\n"),
choices = c("Value in USD" = "value", "Weight in KG" = "weight"),
selected = "value"),
# Plot will not update until user clicks the "Plot" button.
actionButton("get_plot", "Plot"),
br(),
br(),
tags$ul(
tags$li(HTML("Source code for this app can be found
<a href='https://github.com/ChrisMuir/comtrade_plot_shinyapp'>here</a>.
Please report bugs
<a href='https://github.com/ChrisMuir/comtrade_plot_shinyapp/issues'>here</a>.")),
tags$li(HTML("Source for all shipping data is <a href='https://comtrade.un.org/data/'>UN Comtrade</a>
(<a href='https://comtrade.un.org/data/doc/api/'>link</a>
to the full documentation of the UN Comtrade API).")),
tags$li("This app is not affiliated with the United Nations in any way.")
)
),
# Show plot of data returned from the API call.
mainPanel(
plotlyOutput("resPlot", height = "768px") %>% withSpinner()
)
)
))