I would like to create a data frame that asks user for input and stores the variable in each specific cell. I've been looking it up, but cannot find specifically how to do it.
I don't think RStudio offers a user interface. You could build one with shiny
and for example DT
though. DT provides an editable table widget. Here's an example. You could then save df
somewhere.
library(tidyverse)
library(shiny)
library(DT)
df <- tibble(a=rep("Empty",2), b=rep("Empty",2)) # initial dataframe
ui <- fluidPage(
DTOutput("my_table")
)
server <- function(input,output,session){
output$my_table <- renderDT({
cat("render DT\n")
DT::datatable(df,
options = list(lengthChange=FALSE, ordering=FALSE, searching=FALSE,
stateSave=TRUE, scrollX=FALSE, paging=FALSE, info=FALSE),
editable = TRUE
)
})
observeEvent(input$my_table_cell_edit, {
info <- input$my_table_cell_edit
str(info)
i = info$row
j = info$col
v = info$value
cat("my_table edited", i, j, v, "\n")
df[i,j] <- v
print(df)
})
}
shinyApp(ui, server)
How would i use this to where they input it in and it saves the value they input, but also allows for editing if inputted wrong
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.