Created
February 8, 2016 22:14
-
-
Save amarder/a1b2c165963c9efbe4df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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