title: Shiny R: Modifying the variable class
body: <p>I am trying to create a shiny-app that load data-set, present the variable list and their classes and allow the user to modify the class of a selected variable. All the functions in the following code are working except to the last function in the server- observeEvent which not working when trying to modify the variable class. Any suggestions?</p>
  
  <p>Thank you in advance,
  Rami 
  `</p>
  
  <pre><code>rm(list = ls())
  library(shiny)
  library(shinydashboard)
  library(DT)
  
  ui &lt;- dashboardPage(
    dashboardHeader(title = "Shiny Example"),
    #--------------------------------------------------------------------  
    dashboardSidebar(
      sidebarMenu(
        menuItem("Data", tabName = "data", icon = icon("th"))
      )
    ),
    #--------------------------------------------------------------------
    dashboardBody(
    #--------------------------------------------------------------------
        tabItem(tabName = "data",
                fluidPage(
  
                  fluidRow(
                    box(
                      selectInput('dataset', 'Select Dataset', list(GermanCredit = "GermanCredit",
                                                                    cars = "cars",
                                                                    iris = "iris")),
                      title = "Datasets",width = 4, status = "primary",
                      checkboxInput("select_all", "Select All Variable", value = TRUE),
                      conditionalPanel(condition = "input.select_all == false",
                                       uiOutput("show.var"))
                    ),
                    box(
                      title = "Variable Summary", width = 4,  status = "primary",
                      DT::dataTableOutput('summary.data')
  
                    ),
                    box(
                      title = "Modify the Variable Class", width = 4,  status = "primary",
                      radioButtons("choose_class", label = "Modify the Variable Class", 
                                   choices = list(Numeric = "numeric", Factor = "factor", 
                                                  Character = "character"),
                                   selected = "numeric"),
                      actionButton("var_modify", "Modify")
                    )
                  )
                )
        )
    )
  ) 
  
  #--------------------------------------------------------------------
  # Server Function
  #--------------------------------------------------------------------
  server &lt;- function(input, output,session) {
    #--------------------------------------------------------------------
    # loading the data
    get.df &lt;- reactive({
      if(input$dataset == "GermanCredit"){
        data("GermanCredit")
        GermanCredit
      }else if(input$dataset == "cars"){
        data(cars)
        cars
      }else if(input$dataset == "iris"){
        data("iris")
        iris
      }
    })
  
    # Getting the list of variable from the loaded dataset
    var_list &lt;- reactive(names(get.df()))
    # Choosing the variable - checkbox option
    output$show.var &lt;- renderUI({
      checkboxGroupInput('show_var', 'Select Variables', var_list(), selected = var_list())
    })
  
    # Setting the data frame based on the variable selction
    df &lt;- reactive({
      if(input$select_all){
        df &lt;- get.df()
      } else if(!input$select_all){
        df &lt;- get.df()[, input$show_var, drop = FALSE]
      }
      return(df)
    })
  
    # create list of variables
    col.name &lt;- reactive({
      d &lt;- data.frame(names(df()), sapply(df(),class))
      names(d) &lt;- c("Name", "Class") 
      return(d)
    })
  
    # render the variable list into table
    output$summary.data &lt;- DT::renderDataTable(col.name(), server = FALSE, rownames = FALSE,
                                               selection = list(selected = 1, mode = 'single'), 
                                               options = list(lengthMenu = c(5, 10, 15, 20), pageLength = 20, dom = 'p'))
  
  
   # storing the selected variable from the variables list table 
    table.sel &lt;- reactive({
      df()[,which(colnames(df()) == col.name()[input$summary.data_rows_selected,1])]
    })
  
  
  # Trying to modify the variable class  
  observeEvent(input$var_modify,{
      modify.row &lt;- which(colnames(df()) == col.name()[input$summary.data_rows_selected,1])
      if( input$choose_class == "numeric"){
        df()[, modify.row] &lt;- as.numeric(df()[, modify.row])
      } else if( input$choose_class == "factor"){
        df()[, modify.row] &lt;- as.factor(df()[, modify.row])
      } else if( input$choose_class == "character"){
        df()[, modify.row] &lt;- as.character(df()[, modify.row])
      }
    })
  
  }
  
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p>`</p>