-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.R
101 lines (98 loc) · 13.8 KB
/
ui.R
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
94
95
96
97
98
99
100
101
require(shiny)
shinyUI(fluidPage(
titlePanel("Blend Solver 1.0"),
tabsetPanel(
id = "Header",
tabPanel("Introduction",
h1('Introduction.'),
helpText('The program (see the next tab) is split in to two regions. The grey control area on the left is for making choices of how you want to enter data, while the white data/results area on the right is for showing you the data you\'ve currently inputted. Here, you can also edit the data if you\'ve selected to enter it manually. The data you need to input to create your blend is separated into sections which are reflected in the sections below. Note, you only actually need to use the first section. Once you\'ve input/uploaded the data and target, the remaining sections generate default values and you can jump to the bottom of the grey area and hit \'Calculate\' immediately. You only need to worry about the other sections if you want to set some constraints on the blend (e.g. force certain components to be less than some proportion of the blend).'),
helpText('In a little more detail, in each section you have a choice of input methods (either uploading Excel files or manually entering data), as well as giving default values where necessary. When entering data manually, it is better to ignore the +/- buttons and use the appropriate box in the grey area if you need to add rows/columns. The white area on the right of the program shows the input data (whether uploaded or a place to enter manually), and the final results (after clicking \'Calculate\'). Note, you have to click \'Calculate\' at the bottom of the grey area to update results if you change anything, they don\'t update automatically.'),
hr(),
h3('Component Properties and Target Properties.'),
helpText('This section describes how the parameter properties of each potential component of the blend are defined, as well as a target set of parameters for the resulting blend. You can enter the data either by uploading an Excel file (the preferred method for this section - manual for the others), or by manually entering data. In both cases the data should be arranged as: columns are for the potential components of the blend, rows are for the parameters to be matched (we will call this the A matrix). The final column must be the target parameters (we will call this the b vector). The program minimises |Ax = b|^2 to give x - the solution blend vector, subject to some additional criteria defined in subsequent sections. If you input A and b by uploading a file, the first column must be the parameter names. If you do the data manually, ignore column and row names and just enter the data. Obviously, it\'s not the best idea to be setting a target outside any max/min values.'),
helpText('This is what your Excel file should look like (with relevant row/column names):'),
tableOutput('Excel_Example'),
helpText('This is what the same table should look like if entered manually:'),
tableOutput('Manual_Example'),
hr(),
h3('A Set of Equalities.'),
helpText('This section describes a set ot equalities (totals) for each of the components or combination of components - the default being that the sum of components is 1 (all proportions are defined as 0 -> 1 rather than 0 % -> 100 %). But you can set this to < 1 if you need to. Or you can set specific combinations to different values - i.e. if you have 3 components, you can set the first 2 components to 0.55 of the blend, and the third component to 0.45. It will be helpful to know some basic matrix algebra in order to understand how to set this, but it is not a requirement. Essentially you will define a matrix picking out the components of interest with a value of 1, this is the E matrix, and then a vector defining the totals, this is the F vector. The calculation then solves the original blend problem, with the additional restriction that Ex = F, where x is the solution vector. As for defining A and b above, E and F are inputted together in one table, with the first few columns (n = number of components) defining E and last column reserved for F. In the case of setting the sum of all components equal to 1, this is simply a row of 1s - as shown by default. If you want to set something more complicated (e.g. that mentioned a moment ago), then you effectively define two equations. The first defines (Proportion of Component 1) + (Proportion of Component 2) = 0.55, the second defines (Proportion of Component 3) = 0.45, as below. Note, you must have zero entered into unused cells.'),
tableOutput('Example_Equalities'),
helpText('The requirement is a row for each \'group\' of components that you want to set to a specific proportion, with a 1 in each column that picks out the relevant component(s), and the total proportion of those components in the last column. For the specific example mentioned above, you would need to add a row to the default table (using the box in the relevant section in the grey area) and modify the table accordingly - as shown above/below. In general, this is very strict and it\'s better to set constraints to be =< 0.55 rather than 0.55 specifically, so you probably want to leave this section at its default value and use the Constraints section instead.'),
helpText('You can upload a file in a similar manner as for the data and target input (with no Parameter column), or do it manually. For file upload, you will need the following format:'),
tableOutput('Example_Equalities2'),
helpText('For manual input, follow a similar method as for the manual data input - the table should look as earlier in this section.'),
hr(),
h3('A Set of Constraints.'),
helpText('This section is similar to the setting of equalities, except that you can set \'weaker\' constraints, so that it gives the program more flexibility because you specify a component (or group of components) to be >= to or =< to, rather than exactly = to. Generally, this is the preferred option for controlling constraints on the blend. The calculation solves the equation Gx >= H, which is almost identical to the equalities section, except now the components are set to be greater than some value (and you never modify the default entries). The data is defined in the same way as for the equalities. Alternatively, you can set them to be less than some value by inputting -1 instead of 1 in the relevant place, and a negative value in the proportion column H (final column of table). The default just sets all components >= 0 - for obvious reasons (hence minimum of 3 rows if you have 3 components) - you do not want to change this. You may append additional constraints (by adding rows using box in grey area), but the default table that appears should not be adjusted. Again, this data can be entered manually (in an almost identical manner to the setting of equalities) or by Excel upload. Remember, we need the default constraint to be present, so the first section of your table must be the same as the default table (perhaps with additional rows). For example, a valid Excel file would look like:'),
tableOutput('Example_Constraints'),
helpText('The first 3 rows of this table constrains each component to have a proportion >= 0 (which is the default data provided, and what we always want). The fourth row says (Proportion of Component 1) + (Proportion of Component 2) >= 0.2. The fifth row states that the (Proportion of Component 1) + (Proportion of Component 3) <= 0.8. These last two rows are additional constraints and not always necessary, but sometimes useful. And your constraints do not always need to fit some neat value like 1 - we could have set either one of those constraints on its own. The manual input would be the same table (by adding two rows to the default table using the box in the relevant section in the grey area), but without the column titles. Note, it is not possible to set constraints on the final blend properties e.g. Param.1 =< 2.5, you can only weight them (see next section).'),
hr(),
h3('A Set of Weights.'),
helpText('Here you can define a set of weights for the calculation to consider. There are two sets of weightings that can be applied. (1) Weightings on the components - if you want to favour particular components, but don\'t want to set explicit totals or constraints. (2) Weightings on the parameters - if you want a particular parameter to be of importance. The default sets everything of equal importance, but you can arbitrarily scale these up and down as necessary. By default the values chosen are 1/(numer of components) or 1/(number of parameters) as appropriate. In actual fact, it doesn\'t matter what these values are, only the relative size - they could be all 1 or all e. The calculation just weights according to the relative size of the values, so a value of 2.5 means that parameter (or component) is weighted twice as much as one with a value of 1.25. The component and parameter weightings are applied independently and do not directly influence each other. Although they might indirectly - in my experience, parameter weights tend to have the biggest influence on the final blend, but it depends whether you have a parameter that is controlled mainly by one component or not. The construction of weights requires two vectors, one for the weightings for the components, and one for the weightings of the parameters. This is done automatically for you, which you can then edit as necessary. But if you must use a file input for this, you will need two Excel files. The component weights must be a table containing a row of component names and a second row of numbers defining the weightings. The parameter weights must be two columns, the first the parameter names, and the second, the parameter weights. Something like this:'),
tableOutput('Example_Wx'),
tableOutput('Example_Wa'),
hr(),
h3('Resulting in.'),
helpText('Given all this data and constraints etc on the calculation, the program will then calculate the optimum blend to best achieve the targetted parameters. Note, all calculations in this program assume that the parameters are additive. If the properties are not additive the results could still be good enough as an initial trial, but they may give significantly inaccurate results. If the latter is that case, you\'ll have to do some proper Design of Experiment. The results will be in the form of the component proportions (multiply by 100 to get the percentages), and the resulting properties of that blend. Something like this (the component and parameter names are extracted from the initial data table, which is why it\'s better to upload that from an Excel file):'),
tableOutput('Example_Blend'),
tableOutput('Example_Properties')
),
tabPanel("Program",
sidebarLayout(
sidebarPanel(h3("Data and Target Input"),
helpText("This section is for entering in the base data (A) and target data (b). See introduction for more details. The options below will change depending on your choice of input method, and the table will appear in the white area on the right. Once you have successfully input these data, you may skip to the bottom and hit \'Calculate\', or define extra criteria in the intervening sections."),
radioButtons("radio", label = "Input Data",
choices = list("Manual" = "Manual", "File" = "File"),
selected = "File"),
uiOutput('choice'),
hr(),
h3("Define Equalities"),
helpText('This section is for defining the equalities (totals) for the various components. The default setting is to set the total equal to 1.'),
radioButtons("radio2", label = "Input Equalities",
choices = list("Manual" = "Manual", "File" = "File"),
selected = "Manual"),
uiOutput('choice2'),
hr(),
h3("Define Constraints"),
helpText("This section is for defining any constraints you may wish to apply. This is handled in much the same way as the equalities of the previous section. The default is to set the proportion of each component >= 0. You may append rows to the default provided, but do not modify these. An Excel upload will require these as the first (n = number of component) rows."),
radioButtons("radio3", label = "Input Constraints",
choices = list("Manual" = "Manual", "File" = "File"),
selected = "Manual"),
uiOutput('choice3'),
hr(),
h3("Define Weights"),
helpText("This section is for defining how you want to weight the importance of each component and/or of each parameter. The default sets each component of equal importance, and each parameter of equal importance."),
radioButtons("radio4", label = "Input Weights",
choices = list("Manual" = "Manual", "File" = "File"),
selected = "Manual"),
uiOutput('choice4'),
hr(),
actionButton("calculateButton", "Calculate")
),
mainPanel(
h3('This is your component data and the target:'),
uiOutput('inmatrix'),
tableOutput('contents'),
hr(),
h3('These are your defined equalities (totals):'),
uiOutput('totals'),
tableOutput('contents2'),
hr(),
h3('These are your defined constraints (minimums/maximums):'),
uiOutput('constraints'),
tableOutput('contents3'),
hr(),
h3('These are your defined weightings:'),
uiOutput('weights_x'),
uiOutput('weights_a'),
tableOutput('contents4_x'),
tableOutput('contents4_a'),
hr(),
h3('Results:'),
uiOutput('results')
)
)
)
)
))