Skip to content

Instantly share code, notes, and snippets.

@rfaelens
Created January 15, 2020 15:36
Show Gist options
  • Save rfaelens/285ad645e24aba047a1d97899a9fd480 to your computer and use it in GitHub Desktop.
Save rfaelens/285ad645e24aba047a1d97899a9fd480 to your computer and use it in GitHub Desktop.
## Investigation for https://github.com/handsontable/handsontable/issues/2002
## and https://github.com/jrowen/rhandsontable/issues/159
##
ui <- fluidPage(
shinyjs::useShinyjs(),
rhandsontable::rHandsontableOutput("table"),
actionButton("swap", label="Swap borders!"),
actionButton("randomTop", label="Randomize top color"),
actionButton("randomBottom", label="Randomize bottom color")
)
server <- function(input, output) {
myBorders <- reactiveVal(list(
list(
row=2,
col=0,
top=list(width=3, color="cyan"),
bottom=list(width=7, color="green")
)
))
output$table <- rhandsontable::renderRHandsontable({
cat("RENDERING table\n")
df <- tibble(foo=1:5, bar=runif(5))
shinyjs::runjs("HTMLWidgets.find('#table').hot.getPlugin('CustomBorders').clearBorders()")
rhandsontable::rhandsontable(df) %>%
rhandsontable::hot_table(customBorders=myBorders())
})
observeEvent(input$swap, {
val <- myBorders()
val[[1]][c("bottom", "top")] <- val[[1]][c("top", "bottom")]
cat("New customBorders:\n")
print(val)
myBorders(val)
})
observeEvent(input$randomTop, {
val <- myBorders()
val[[1]][["top"]][["color"]] <- sample(c("green", "orange", "blue", "cyan"), 1)
cat("New customBorders:\n")
print(val)
myBorders(val)
})
observeEvent(input$randomBottom, {
val <- myBorders()
val[[1]][["bottom"]][["color"]] <- sample(c("green", "orange", "blue", "cyan"), 1)
cat("New customBorders:\n")
print(val)
myBorders(val)
})
}
app <- shiny::shinyApp(ui=ui, server=server)
shiny::runApp(app)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment