I have a table that I want to update in Shiny based on the inputs. Pretty Basic.
The table structure is as follows:
-It's a single row with many columns.
-The Columns to be updated are numbered(lets say 1-10).
-These columns are like identifiers.
| OldData | TEXT | TEXT | TEXT | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| First | Character | Character | Character | Numeric | Numeric | Numeric | Numeric | Numeric | Numeric | Numeric | Numeric | Numeric | Numeric |
The input table is variable in size and here is its structure:
Rows in the first column contain how ever many of the identifiers we need.
Rows in the second column contain the the value that needs to replace the corresponding identifiers's value in the old data frame
| NewData | IDColumn | VALUEColumn |
|---|---|---|
| First | 8 | Numeric |
| Second | 4 | Numeric |
| Third | 5 | Numeric |
| Fourth | 1 | Numeric |
| Fifth | 7 | Numeric |
The end result is newly named data frame that is the same structure as the first but with the values updated with the info from the new dataframe.
Updated Table Structure:
| OldData | A | B | C | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| First | Character | Character | Character | NewNumeric | OldNumeric | OldNumeric | NewNumeric | NewNumeric | OldNumeric | NewNumeric | NewNumeric | OldNumeric | OldNumeric |
I thought I would try a for-loop but am unsure where to start.
updated_table_df <- reactive({
for (i in 1:nrow(newtable$columnA)){
for(v in 1:nrow(newtable$columnB)){
updated_table <- oldtable() %>%
replace(.,i,v) %>%
select(1:10) # This was an attempt to output the new table to see if it worked
}
}
})
I hope this made sense. If you have any questions let me know.
Thanks.
dput()or other valid R syntax so that the sample data copy/pasteable.oldtableseems clear, butnewtableandupdated_tablearen't so clear...oldtableandnewtablecombine intoupdated_table. I tried to update according to be more clear.