I am building a shiny datatable with one column for numericinput and the other reactive to the input. It is similar to what you can do in excel with equation embedded in cells. I am giving iris as example below and trying to calculate petal area. So peal area equals Petal.Length*Petal.Width/Adjust. The adjust parameter will be typed in by user to adjust area. A similar question was asked here but with no direct answer. Insert a numeric input for each row - R Shiny
library(shiny)
library(DT)
library(dplyr)
ui <- basicPage(
DT::dataTableOutput('x1')
)
server <- function(input, output, session) {
# create a character vector of shiny inputs
shinyInput = function(FUN, len, id, ...) {
inputs = character(len)
for (i in seq_len(len)) {
inputs[i] = as.character(FUN(paste0(id, i), label = NULL, ...))
}
inputs
}
# obtain the values of inputs
shinyValue = function(id, len) {
unlist(lapply(seq_len(len), function(i) {
value = input[[paste0(id, i)]]
if (is.null(value)) 1 else value
}))
}
# a sample data frame
DF <- reactive(
iris <- iris %>%
mutate(
adjust = shinyInput(numericInput, nrow(iris), 'adj', value = 1),
Petal_Area = Petal.Length*Petal.Width/shinyValue('adj', nrow(iris))
)
)
# render the table containing shiny inputs
output$x1 = DT::renderDataTable(
# use slider to control number of rows shown in table
DF(), server = FALSE, escape = FALSE, options = list(
preDrawCallback = JS('function() {
Shiny.unbindAll(this.api().table().node()); }'),
drawCallback = JS('function() {
Shiny.bindAll(this.api().table().node()); } ')
)
)
}
shinyApp(ui, server)
rhandsontable
solves that problem, I would be surprised if it did. But then again the idea ofrhandsontable
is to manipulate a table like in Excel. I just don't know how that package deals with bigger tables than on github tutorial. – 5th