Skip to content

Instantly share code, notes, and snippets.

@amarder
Created February 8, 2016 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amarder/a1b2c165963c9efbe4df to your computer and use it in GitHub Desktop.
Save amarder/a1b2c165963c9efbe4df to your computer and use it in GitHub Desktop.
---
title: "Creating an rhandsontable widget"
output: html_document
runtime: shiny
---
I want to set up a [Shiny widget](http://rmarkdown.rstudio.com/authoring_shiny_widgets.html) so it's easy to use [rhandsontable](http://jrowen.github.io/rhandsontable/).
```{r}
library(rhandsontable)
library(shiny)
hands_on_table <- function(reactive_data) {
ui <- fluidPage(fluidRow(column(12, rHandsontableOutput("data"))))
server <- function(input, output, session) {
print('hi')
output$data <- renderRHandsontable({rhandsontable(reactive_data())})
return(output)
}
app <- shinyApp(ui=ui, server=server)
return(app)
}
```
Imagine we have some simple data that we want the user to edit:
```{r}
make_reactive <- function(initial_data) {
reactive({
if (is.null(input$data))
return(initial_data)
else
return(hot_to_r(input$data))
})
}
cars <- make_reactive(data.frame(
name=c('Camry', 'Accord'),
price=c(10, 11)
))
hands_on_table(cars)
```
```{r}
renderTable({
cars()
})
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment