I am creating a simple R shiny app where the user uploads a .CSV file and it renders the data table in the main panel, as well as highlights column names automatically in the 'select column' section.
What I am looking for is:
How can values be replaced? (from old to new values). as an example How should I modify the value 100 to 500 in the 'range' column by referencing the column name in the 'select column'?
Note: I have also included a textInput
box to mention the old and new values.
csv data
ID Type Category Range
21 A1 B1 100
22 C1 D1 200
23 E1 F1 300
app.R
library(shiny)
library(shinydashboard)
library(reshape2)
library(DT)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
fluidRow(
fileInput("file1","Uplaod Data",buttonLabel = "Browse..",placeholder = "No file Selected"),
checkboxInput("header", "Header", TRUE),
#actionButton("Splitcolumn", "SplitColumn"),
selectInput(inputId='selectcolumn', label='select column', ''),
#actionButton("deleteRows", "Delete Rows"),
textInput('oldvalue', label='Oldvalue'),
textInput('newvalue', label='New value to replace')
),
mainPanel(
DTOutput("table1"),
),
)
)
server <- function(session, input, output) {
rv <- reactiveValues(data = NULL)
observeEvent(input$file1, {
file <- input$file1
ext <- tools::file_ext(file$datapath)
req(file)
validate(need(ext == "csv", "Please upload a csv file"))
rv$data <- read.csv(file$datapath, header = input$header)
updateSelectInput(session, 'selectcolumn', 'select column', names(rv$data))
})
observeEvent(input$Splitcolumn, {
rv$data <- splitColumn(rv$data, input$selectcolumn)
})
observeEvent(input$deleteRows,{
if (!is.null(input$table1_rows_selected)) {
rv$data <- rv$data[-as.numeric(input$table1_rows_selected),]
}
})
output$table1 <- renderDT({
rv$data
})
}
shinyApp(ui, server)