My current web app asks users to upload a CSV file. Then a series of data cleansing options are provided (ex. remove null rows, impute nulls, change datatypes). My issue is that I wish for the reactive dataframe variable (named 'workingDf') to be modified by the cleansing options. This should be reflected in the table output which presents the user their uploaded data. Thus, if they select to remove nulls, that table should show as such.
Perhaps, being new to Shiny, I cannot quite grasp how to dynamically modify uploaded dataframes, but this is a large aspect of the web app I wish to build.
TLDR
Would like to change reactive value through user input dynamically (change and un-change). Also, would change any UI elements like renderDataTable dynamically.
The following is a condensed version of the application, still functional, that isolates the issue I wish to resolve. My attempt to make the workingDf dataframe be dynamically altered by server code is commented out below.
UI
##UI design
ui <- fluidPage(
useShinyjs(),
extendShinyjs(text = jscode),
#CSS theme
theme = shinytheme("united"),
# Title for page
titlePanel("DataOneTwo"),
#sidebar, complete layout
sidebarLayout(
#sidebar, inputs
#these elements remain throughout page interactions/experience
sidebarPanel(
helpText("LOAD: "),
#user input: selection and upload of CSV file factors
fileInput(inputId = "fileIn", label = "Upload CSV Data File",
multiple = FALSE,
accept = c("text/csv",
"text/comma-separated-values,
text/plain",
".csv"),
width = NULL),
#visual horizontal line
tags$hr(),
#user input: display headers from CSV
checkboxInput("header", "Header", TRUE),
#user input: selecting CSV separator
radioButtons("sep", "Separator",
choices = c(Semicolon = ";",
Comma = ",",
Tab = "\t"),
selected = ","),
helpText("EXPLORE: "),
#user input: selection dropdown for CSV columns
selectInput("selectIn", "Select Column (Attribute) to Explore: ", choices = "Waiting for Upload... ")
),
#sidebar, ouputs
mainPanel(
#set tabs for page
tabsetPanel(
##
###PANEL: LOAD###
###See server for corresponding comment and backend functionality###
##
tabPanel("Load",
#Javascript dynamic output
dataTableOutput("table")
),
##
###PANEL: CLEAN###
###See server for corresponding comment and backend functionality###
##
tabPanel("Clean",
#defines column
fluidRow(
column(width = 4,
helpText("Change datatype (to numeric or to character): "),
#user input: datatype converter
radioButtons("dataType", "Data type converter",
c(toNumeric = 'To Numeric',
toCharacter = 'To Character')
),
#displays that execution of datatype conversion is complete
verbatimTextOutput("dataConfirm")
),
column(width = 4, offset = 1,
helpText("Select column, then choose cleaning method: "),
helpText("Removes all rows with NULLs in column."),
#output of null columns removal, head only,
verbatimTextOutput("nullCount"),
verbatimTextOutput("nullCount_2"),
#user input: binary for whether to remove nulls
checkboxGroupInput('null', 'Remove NULL rows: ',
c(columns = 'columns')
)
)
)
)
)
)
)
)
Server
server <- function(input, output, session){
#PANEL: LOAD
#reactive, CSV input field, stores are variable
workingDf <- reactive({
rawDf <- input$fileIn
req(rawDf)
# if (is.null(rawDf))
# return(NULL)
lookDf <- read.csv(rawDf$datapath, header = input$header, sep=input$sep)
return(lookDf)
})
#Render dynamic, interative table from JavaScript library: DataTables
output$table <- renderDataTable({
workingDf()
}
, options = list(pageLength = 10)
)
observe({
updateSelectInput(session, "selectIn", choices = colnames(workingDf()))
})
}
shinyApp(ui = ui, server = server)
If my question is not clear, please let me know and I'll attempt to clarify. Thank you in advance R Studio Community.