New Column Containing Row Number in Reactive Data Frame



Say I have a data frame called df. I can create a new column called ID in df that lists the row number for the data frame using R.

df$ID <-

Now let’s say I have a reactive data frame called df().

How can I accomplish the same thing?


I think you will either have to do that within the reactive definition for df, add the ID in the client of df(), or create a new reactive based on df, e.g.

df_with_ID = reactive({
  df_new = df()
  df_new$ID =


Yes, this does seem to work. I didn’t pick up that this was the answer to problems like these after watching all the tutorials on the internet. Seems to be a very important concept. Thanks for sharing.