Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
Add Comment
Please, Sign In to add comment