Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have table in Shiny filled by user?

Tags:

r

datatable

shiny

I want users of my Shiny app to fill in the values of a 2x2 table with row and column names. Of course, I could do it with 4 input boxes, but I assume that it will be tricky to position everything neatly. Despite that, I would prefer a table layout such as the one provided by the DT package. Thus, my question is: Is it possible to have a datatable (or something similar) filled by the user?

like image 506
Joe Avatar asked Oct 12 '17 10:10

Joe


1 Answers

You can use shinysky

devtools::install_github("AnalytixWare/ShinySky") package

or rhandsontable to do what you want:

rm(list = ls())
library(shiny)
library(shinysky)

server <- shinyServer(function(input, output, session) {

  # Initiate your table
  previous <- reactive({mtcars[1:10,]})

  MyChanges <- reactive({
    if(is.null(input$hotable1)){return(previous())}
    else if(!identical(previous(),input$hotable1)){
      # hot.to.df function will convert your updated table into the dataframe
      as.data.frame(hot.to.df(input$hotable1))
    }
  })
  output$hotable1 <- renderHotable({MyChanges()}, readOnly = F)
  output$tbl = DT::renderDataTable(MyChanges())
})

ui <- basicPage(mainPanel(column(6,hotable("hotable1")),column(6,DT::dataTableOutput('tbl'))))
shinyApp(ui, server)

enter image description here

like image 177
Pork Chop Avatar answered Nov 01 '22 12:11

Pork Chop