logo
down
shadow

Editing data frame after reactive upload in R shiny


Editing data frame after reactive upload in R shiny

Content Index :

Editing data frame after reactive upload in R shiny
Tag : r , By : Don Changer
Date : November 28 2020, 04:01 AM

I wish this helpful for you The code in the server() function really should only set up reactive objects and respond to reactive events. You shouldn't have any data manipulation data in the body of the server() function itself because when that runs the data is not yet available. Something like this makes more sense
ui <- fluidPage(
  fluidPage(
    titlePanel("Uploading Files"),
    fileInput('myFile', 'Choose File'),
    tableOutput('contents')
  )
)
server <- function(input, output) {

  a1 <- reactive({
    req(input$myFile)
    read_excel(input$myFile$datapath)
  })

  newdata <- reactive({
    a1 <- a1()
    x <- as.POSIXct(a1$Month)

    a1$mo <- strftime(x, "%m")
    a1$yr <- strftime(x, "%Y")
    a1$qrt <- quarter(x, with_year = FALSE, fiscal_start = 01)

    newdata <- a1[grepl("Y", a1$`Quota Held Flag`),]

    #fixing participation column into categorical for donut chart
    newdata$Participation[is.na(newdata$Participation)] <- 0
    newdata$Participation <- factor(newdata$Participation, labels = c("0-99%","100%")) 

    #grouping data
    newdata %>%
      group_by(yr, mo, qrt)     
  })

  output$contents <- renderTable(        
    newdata()        
  )

}
shinyApp(ui = ui, server = server)

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

R shiny modify reactive data frame


Tag : r , By : joshski
Date : March 29 2020, 07:55 AM
With these it helps I think this question can be closed thanks to the answer for @dieter-menne to another question about subsetting reactive data frames. The point is to create a new local variable, similar to @john-paul suggestion.
Please take a look at https://stackoverflow.com/a/20569512/709777

Reactive column names in reactive data frame shiny


Tag : r , By : Chaz
Date : March 29 2020, 07:55 AM
wish help you to fix your issue If I understood the question correctly, you might need something like that:
  combined_final_rename<-reactive({
    d <- combined_final()
    colnames(d)[colnames(d)=='Rev'] <- namerev()
    d
  })

R shiny - editing a data frame and shiny takes the last number edited


Tag : r , By : mikhaelrasputin
Date : March 29 2020, 07:55 AM
Hope that helps The issue is that the app does not know when you want things to change. For example, if you wanted to change two rows of the same columns to be "4" all you would do is change the row number. But shiny can't tell if that is what you want to do when you change the row number, or if you are going to change the column number as well.
One way to deal with this is to put an actionButton in the ui and then only change the values when the button is pushed. So to the ui add below the 3rd uiOutput in the sidebarPanel:
actionButton(inputId=modificar, label="Modifica") 
result <- reactive({
    input$modificar
    isolate({
      if(is.null(input$variable) || is.null(input$contrato) ) {
        return()
         } else {
         variables[which(input$contrato == variables$garantias),    
             which(input$variable == colnames(variables))] <<-  
             as.numeric(input$var)
         return(variables)
         }
   })
 })

R shiny: How to get an reactive data frame updated each time pressing an actionButton without creating a new reactive da


Tag : r , By : Gabriel
Date : March 29 2020, 07:55 AM
around this issue Below is a working solution. I created a reactiveValues to store the dataframe. When a file is chosen, the dataframe gets populated. When the delete button is pressed, that same dataframe gets a row deleted. The table always outputs whatever that dataframe object is holding. I hope this code can be a good learning material
runApp(shinyApp(
ui=(fluidPage(
  titlePanel("amend data frame"),

  mainPanel(
    fileInput("file", "Upload file"),

    numericInput("Delete", "Delete row:", 1, step = 1),
    actionButton("Go", "Delete!"),

    tableOutput("df_data_out")
  )
)),
server = (function(input, output) {
  values <- reactiveValues(df_data = NULL)

  observeEvent(input$file, {
    values$df_data <- read.csv(input$file$datapath)
  })

  observeEvent(input$Go, {
    temp <- values$df_data[-input$Delete, ]
    values$df_data <- temp

  })

  output$df_data_out <- renderTable(values$df_data)
})))

shiny: reactive a column in a data frame


Tag : development , By : Ted Leung
Date : March 29 2020, 07:55 AM
like below fixes the issue Make your data reactive, bind a change function to your table and then update the values on change (now with sum column):
library(shinydashboard)
library(shiny)
library(data.table)
library(rhandsontable)

DF = data.frame(num = 1:10, price = 1:10,
                stringsAsFactors = FALSE)
DF = rbind(DF, c(0,0,0))

ui = fluidPage(
  titlePanel("sample"),
  fluidRow(box(rHandsontableOutput("hot", height = 400)))  
)
server = function(input, output) {
  data <- reactiveValues(df=DF)

  output$hot <- renderRHandsontable({
    isolate({
      data$df$total       <- data$df$num*data$df$price
      print(sum(data$df$num*data$df$price) )
      data$df$total[11]   <- sum(data$df$num*data$df$price) 
    })
    rhandsontable(data$df, selectCallback = TRUE) 
  })

  observeEvent(input$hot$changes,{
    print('Change')

    # Get changed value
    row.i <- input$hot_select$select$r
    col.i <- input$hot_select$select$c
    new.v <- unlist( input$hot$changes$changes )
    new.v <- new.v[[length(new.v)]]

    # Save and update the value
    data$df[row.i,col.i] <- new.v
    data$df$total <- data$df$num[row.i]*data$df$price[row.i]

    # Calculate Sum 
    data$df$total[11] <- sum(data$df$total)
  })

}
shinyApp(ui, server)
Related Posts Related QUESTIONS :
  • scale_fill_viridis_c color bar on a log scale
  • How to change the lab name corresponding to function in ggplot
  • R, filtering for an element in a list in a dataframe cell
  • Extracting only bottom temperature from 4d NetCDF file
  • How to add/wrap lines of text to .tex with .sh script
  • R - building new variables from sequenced data
  • Sum rows values one after the other
  • Nesting ifelse inside summarytools
  • How best to divide different levels of a factor by one another in dataframe in R?
  • Why does my code run multiple times before I type data into the table? How do I make an action button that creates a tab
  • How to impute missing values not at random?
  • Set the y limits of an added average line of a plotly plot
  • how to calculate a new column after grouping with dplyr
  • Extract data from rows creating new columns using R
  • Create a filled area line plot with plotly
  • When do I need parentheses around an if statement to control the sequence of a formula in R?
  • my graph in ggplot2 contains an "e" character in y-axis
  • Making variables immutable in R
  • R: Difference between the subsequent ranks of a item group by date
  • Match data within multiple time-frames with dplyr
  • Conditional manipulation and extension of rows in data.table also considering previous extensions without for-loop
  • Conditional formula referring to preview row in DF not working
  • Set hoverinfo text in plotly scatterplot
  • Histogram of Sums from Categorical/Binary Data
  • Efficiently find set differences and generate random sample
  • Find closest points from data set B to point in data set A, using lat long in R
  • dplyr join on column A OR column B
  • Replace all string if row starts with (within a column)
  • Is there a possibility to combine position_stack and nudge_x in a stacked bar chart in ggplot2?
  • How can I extract bounding boxes in a row-wise manner using R?
  • How do I easily sum up values in different columns?
  • Reading numeric Date value from CSV file to data.frame in "R"
  • R programming: creating a stacked bar graph, with variable colors for each stacked bar
  • How to identify all columns that contain binary representation
  • Filter different groups by different factor levels
  • Saving .xlsx file to disc, form http post request
  • Add an "all" option under the filter that selects the number of rows displayed in a datatable
  • How to select second column of every xts in list
  • Generate a frequency dataframe out of an input dataframe
  • Why manual autocorrelation does not match acf() results?
  • Merge 3 dataframes which are different to each other
  • remove adjacent duplicates from string
  • How to change the position of stacked stacked bar chart in ggplot in R?
  • How to divide each of a range a variables by a second range of variables in R
  • Why do I need to assemble vector before scaling in Spark?
  • How to select individuals which appear in multiple groups?
  • How can I fill columns based on values in another column?
  • 32 bit R and 64 bit R: output differs
  • Remove a single backslash in paste0 output
  • ggplot2 different label for the first break
  • TSP in R, with given distances
  • How to find the given value from the range of values?
  • Solution on R group by issue _ multiple combination
  • Transform multiple columns with a function that uses different arguments per column
  • How can I parse a string with the format "1/16/2019 1:24:51" into a POSIXct or other date variable?
  • How to plot a box plot in R for outlier detection for a huge number of rows?
  • How to change column name according to another dataframe in R?
  • `sjPlot::tab_df()`--how to set the number of decimal places?
  • time average for specific time range in r
  • joining dataframes by closest time and another key in r
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com