Skip to content

Commit

Permalink
fix(shared): Disable menu options in CAS mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tmelliott committed Dec 10, 2023
1 parent bb8f98f commit 4408be4
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 33 deletions.
8 changes: 8 additions & 0 deletions panels/B2_ExportDataset/2_export.dataset.panel-server.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@


output$save.data.panel = renderUI({
if (!is.null(session$userData$LITE_VERSION) &&
session$userData$LITE_VERSION == "CAS") {
return(
mainPanel(
h4("This feature is not available with the current configuration.")
)
)
}
save.data.panel(get.data.set())
})

Expand Down
102 changes: 102 additions & 0 deletions panels/E4_CreateVariables/3_create.variables.help.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>Create variables</title>
<style type="text/css">
body {
font-family: sans-serif;
max-width: 800px;
margin: auto;
padding: 1em;
line-height: 1.5;
box-sizing: border-box;
}
body, .footnotes, code { font-size: .9em; }
li li { font-size: .95em; }
*, *:before, *:after {
box-sizing: inherit;
}
pre, img { max-width: 100%; }
pre, pre:hover {
white-space: pre-wrap;
word-break: break-all;
}
pre code {
display: block;
overflow-x: auto;
}
code { font-family: 'DejaVu Sans Mono', 'Droid Sans Mono', 'Lucida Console', Consolas, Monaco, monospace; }
:not(pre) > code, code[class] { background-color: #F8F8F8; }
code.language-undefined, pre > code:not([class]) {
background-color: inherit;
border: 1px solid #eee;
}
table {
margin: auto;
border-top: 1px solid #666;
}
table thead th { border-bottom: 1px solid #ddd; }
th, td { padding: 5px; }
thead, tfoot, tr:nth-child(even) { background: #eee; }
blockquote {
color: #666;
margin: 0;
padding-left: 1em;
border-left: 0.5em solid #eee;
}
hr, .footnotes::before { border: 1px dashed #ddd; }
.frontmatter { text-align: center; }
#TOC .numbered li { list-style: none; }
#TOC .numbered { padding-left: 0; }
#TOC .numbered ul { padding-left: 1em; }
table, .body h2 { border-bottom: 1px solid #666; }
.body .appendix, .appendix ~ h2 { border-bottom-style: dashed; }
.footnote-ref a::before { content: "["; }
.footnote-ref a::after { content: "]"; }
section.footnotes::before {
content: "";
display: block;
max-width: 20em;
}

@media print {
body {
font-size: 12pt;
max-width: 100%;
}
tr, img { page-break-inside: avoid; }
}
@media only screen and (min-width: 992px) {
pre { white-space: pre; }
}
</style>
</head>
<body>
<div class="include-before">
</div>
<div class="frontmatter">
<div class="title"><h1>Create variables</h1></div>
<div class="author"><h2></h2></div>
<div class="date"><h3></h3></div>
</div>
<div class="body">
<h5 id="create-variables">Create variables</h5>
New columns or variables can be generated with this calculator like module. A
set of controls can be used to generate a function for a new column.
- A dropdown menu can be used to select variables from the current data set.
- Several operators can be used to construct a function.
- Twelve buttons can be used to add numbers to the function or delete part of
the function.
- In a text filed the name of the new variable can be specified. The default
name is "new.name". A number is added to the name in case more than one variable
is generated.
- Next to the text field, the formula is displayed.
- The "Create Variable" button adds the new variable to the data.
- A information message tells whether the function can produce a variable.
</div>
<div class="include-after">
</div>
</body>
</html>
85 changes: 52 additions & 33 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@ shinyServer(function(input, output, session) {
values$transform.text = ""
values$create.variables.expression.text = ""

# TODO: generalise this
if(!is.null(session$userData$LITE_VERSION) && session$userData$LITE_VERSION == "CAS"){
values$data.sample = NULL
values$sample.row = NULL
values$sample.num = NULL
}
# TODO: generalise this / does it work?
observe({
if(!is.null(session$userData$LITE_VERSION) && session$userData$LITE_VERSION == "CAS"){
values$data.sample = NULL
values$sample.row = NULL
values$sample.num = NULL
}
})
# dummy variable to update whole panels when the data
# set is switched but not updated when data is changed.
updatePanel = reactiveValues()
Expand Down Expand Up @@ -539,20 +541,6 @@ shinyServer(function(input, output, session) {
examples = tabPanel("Dataset Examples", uiOutput('switch.data.panel'))
)
import_tabs = do.call("navbarMenu", c("File", unname(all_import_tabs)))

observe({
if(!is.null(session$userData$LITE_VERSION) &&
session$userData$LITE_VERSION == "CAS") {
new_import_tabs = all_import_tabs[names(all_import_tabs) != "export"]
removeTab(inputId = "selector", target = "File")
insertTab(
inputId = "selector",
do.call("navbarMenu", c("File", unname(new_import_tabs))),
target = "About",
position = "after"
)
}
})

#
visualize_tabs = tabPanel("Visualize", value = "visualize", uiOutput("visualize.panel"))
Expand Down Expand Up @@ -609,12 +597,9 @@ shinyServer(function(input, output, session) {
uiOutput("frequency.tables")
)
)
if(!is.null(session$userData$LITE_VERSION) && session$userData$LITE_VERSION == "CAS") {
row_ops_tabs = NULL
}

#
manipulate_tabs = list(
all_manipulate_tabs = list(
convert = tabPanel("Convert to categorical", uiOutput("convert.to.categorical")),
categorical = tabPanel("Categorical variables", uiOutput("categorical.variables")),
numeric = tabPanel("Numeric variables", uiOutput("numeric.variables")),
Expand All @@ -626,13 +611,10 @@ shinyServer(function(input, output, session) {
# reshape = tabPanel("Reshape dataset", uiOutput("reshape.data")),
delete = tabPanel("Delete variables", uiOutput("remove.columns"))
)
if(!is.null(session$userData$LITE_VERSION) && session$userData$LITE_VERSION == "CAS") {
manipulate_tabs = manipulate_tabs[!(names(manipulate_tabs) %in% c("create"))]
}
manipulate_tabs = do.call("navbarMenu", c("Manipulate variables", unname(manipulate_tabs)))
manipulate_tabs = do.call("navbarMenu", c("Manipulate variables", unname(all_manipulate_tabs)))

#
advance_tabs = list(
all_advance_tabs = list(
quick = tabPanel("Quick explore", uiOutput("quick.explore")),
time_series = tabPanel("Time Series", value = "timeSeries", uiOutput("timeseries.panel")),
model = tabPanel("Model Fitting", value = "regression", uiOutput("modelfitting.panel")),
Expand All @@ -642,10 +624,7 @@ shinyServer(function(input, output, session) {
multivariate = tabPanel("Multivariate", uiOutput("multivariate.panel")),
vit = tabPanel("VIT", uiOutput("VIT.panel"))
)
if(!is.null(session$userData$LITE_VERSION) && session$userData$LITE_VERSION == "CAS") {
advance_tabs = advance_tabs[names(advance_tabs) %in% c("multiple", "multivariate")]
}
advance_tabs = do.call("navbarMenu", c("Advanced", unname(advance_tabs)))
advance_tabs = do.call("navbarMenu", c("Advanced", unname(all_advance_tabs)))

if(!is.null(import_tabs)) {
insertTab(
Expand Down Expand Up @@ -685,4 +664,44 @@ shinyServer(function(input, output, session) {
)
)

# TODO: refactor this (issue #345)
observe({
if(!is.null(session$userData$LITE_VERSION) &&
session$userData$LITE_VERSION == "CAS") {

# remove Export from File menu
new_import_tabs = all_import_tabs[names(all_import_tabs) != "export"]
removeTab(inputId = "selector", target = "File")
insertTab(
inputId = "selector",
do.call("navbarMenu", c("File", unname(new_import_tabs))),
target = "About",
position = "after"
)

# remove row ops
removeTab(inputId = "selector", target = "Dataset")

# remove Create from Maniuplate Variables menu
new_manipulate_tabs = all_manipulate_tabs[names(all_manipulate_tabs) != "create"]
removeTab(inputId = "selector", target = "Manipulate variables")
insertTab(
inputId = "selector",
do.call("navbarMenu", c("Manipulate variables", unname(new_manipulate_tabs))),
target = "Advanced",
position = "before"
)

# remove all except 'Multiple response' from Advanced menu
new_advance_tabs = all_advance_tabs[names(all_advance_tabs) %in% c("multiple", "multivariate")]
removeTab(inputId = "selector", target = "Advanced")
insertTab(
inputId = "selector",
do.call("navbarMenu", c("Advanced", unname(new_advance_tabs))),
target = "Manipulate variables",
position = "after"
)
}
})

})

0 comments on commit 4408be4

Please sign in to comment.