Spaces:
Sleeping
Sleeping
Update app.R
Browse files
app.R
CHANGED
|
@@ -90,22 +90,22 @@ server <- function(input, output, session) {
|
|
| 90 |
# Apply R script to modify data
|
| 91 |
observeEvent(input$apply_script, {
|
| 92 |
req(input$r_script)
|
| 93 |
-
req(original_data()) #
|
| 94 |
|
| 95 |
tryCatch({
|
| 96 |
-
#
|
| 97 |
df <- original_data()
|
| 98 |
|
| 99 |
-
#
|
| 100 |
env <- new.env()
|
| 101 |
-
env$data <- df #
|
| 102 |
|
| 103 |
-
eval(parse(text = input$r_script), envir = env) #
|
| 104 |
|
| 105 |
-
#
|
| 106 |
modified_data(env$data)
|
| 107 |
|
| 108 |
-
#
|
| 109 |
output$modified_data_table <- renderDT({
|
| 110 |
datatable(modified_data(), options = list(pageLength = 10, scrollX = TRUE))
|
| 111 |
})
|
|
@@ -121,7 +121,7 @@ server <- function(input, output, session) {
|
|
| 121 |
crosstab <- eventReactive(input$generate_crosstab, {
|
| 122 |
req(input$col_vars, input$row_vars)
|
| 123 |
|
| 124 |
-
#
|
| 125 |
df <- if (input$data_source == "original") {
|
| 126 |
original_data()
|
| 127 |
} else {
|
|
|
|
| 90 |
# Apply R script to modify data
|
| 91 |
observeEvent(input$apply_script, {
|
| 92 |
req(input$r_script)
|
| 93 |
+
req(original_data()) # Ensure that the original data has been loaded
|
| 94 |
|
| 95 |
tryCatch({
|
| 96 |
+
# Take the original data
|
| 97 |
df <- original_data()
|
| 98 |
|
| 99 |
+
# Evaluate the script in a specific environment
|
| 100 |
env <- new.env()
|
| 101 |
+
env$data <- df # The original data is stored in the evaluation environment
|
| 102 |
|
| 103 |
+
eval(parse(text = input$r_script), envir = env) # Evaluate the script
|
| 104 |
|
| 105 |
+
# Take the modification results from the environment
|
| 106 |
modified_data(env$data)
|
| 107 |
|
| 108 |
+
# Display the modified data in the Modified Data tab
|
| 109 |
output$modified_data_table <- renderDT({
|
| 110 |
datatable(modified_data(), options = list(pageLength = 10, scrollX = TRUE))
|
| 111 |
})
|
|
|
|
| 121 |
crosstab <- eventReactive(input$generate_crosstab, {
|
| 122 |
req(input$col_vars, input$row_vars)
|
| 123 |
|
| 124 |
+
# Select data based on the selected source
|
| 125 |
df <- if (input$data_source == "original") {
|
| 126 |
original_data()
|
| 127 |
} else {
|