Using visual elements, a dataframe is created.
I want to update any cell of this table, using visual elements.
I don't understand where my mistake is.
Save button doesn't work.
makeTab <- function(x, y) {
tb <- data.frame(mes = 1:y)
for (i in 2:x) {
tb <- data.frame(tb, mes = 1:y)
}
return(tb)
}
# ========= test makeTab() function
t <- makeTab(x = 3, y = 8)
t
# =================
library(shiny)
ui <- fluidPage(
sliderInput(
inputId = 'ncol',
label = 'Columns',
value = 7,
min = 1,
max = 10,
step = 1,
ticks = T,
),
sliderInput(
inputId = 'nrow',
label = 'Rows',
value = 8,
min = 1,
max = 20,
step = 1,
ticks = T,
),
# ============ set column number for editing
sliderInput(
inputId = 'ncolEdit',
label = 'Col for edit',
value = 3,
min = 1,
max = 10,
step = 1,
ticks = T,
),
# ============ set row number for editing
sliderInput(
inputId = 'nrowEdit',
label = 'Row for edit',
value = 4,
min = 1,
max = 20,
step = 1,
ticks = T,
),
# ============ edit cell
textInput(
inputId = 'val',
label = 'Volume',
value = '100'
),
actionButton(inputId = 'btSave',
label = 'Save' ),
tableOutput(outputId = 'tab'),
)
#=================================
server <- function(input, output) {
#---------- create table
tb <- reactive({
r <- makeTab(x = input$ncol, y = input$nrow)
return(r)
})
#----------- save new value to table - does not work
# tb <- eventReactive(
# eventExpr = input$btSave,
# valueExpr = {
# tb[input$nrowEdit, input$ncolEdit] <- input$val
# })
output$tab <- renderTable(expr = {tb()})
}
#=================================
shinyApp(ui = ui, server = server)