R Shiny, how to modify reactive value based on user input?

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.

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 design
ui <- fluidPage(

  extendShinyjs(text = jscode),

  #CSS theme
  theme = shinytheme("united"),

  # Title for page

  #sidebar, complete layout

    #sidebar, inputs
    #these elements remain throughout page interactions/experience

      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",
                width = NULL),

      #visual horizontal line 

      #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

      #set tabs for page

        ###PANEL: LOAD###
        ###See server for corresponding comment and backend functionality###

                 #Javascript dynamic output

        ###PANEL: CLEAN###
        ###See server for corresponding comment and backend functionality###


                 #defines column
                   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


                   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, 

                          #user input: binary for whether to remove nulls
                          checkboxGroupInput('null', 'Remove NULL rows: ',
                                             c(columns = 'columns')



server <- function(input, output, session){


  #reactive, CSV input field, stores are variable
  workingDf <- reactive({
    rawDf <- input$fileIn


    # if (is.null(rawDf))
    #   return(NULL)

    lookDf <- read.csv(rawDf$datapath, header = input$header, sep=input$sep)


  #Render dynamic, interative table from JavaScript library: DataTables
  output$table <- renderDataTable({
  , options = list(pageLength = 10)

    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.

It would even be better if you can simplify the example code a bit more. And, usually tables have NAs not NULL values (at least how R reads from a csv file). Are you sure that you want to remove the NULL?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.