Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you call a javascript method on a htmlwidget (jsoneditor) in shiny?

I'm trying to use jsonedit from the listviewer package in a shiny app and want to display the tree fully expanded by default. There isn't an option to do this in the jsonedit() function, but the underlying javascript object has an .expandAll() method which should do it. How do I call this method from R shiny? My attempt below doesn't work either in a shiny app or directly in R.

library(shiny)
library(listviewer)
library(magrittr)
library(htmlwidgets)

x <- list(a=1,b=2,c=list(d=4,e='penguin'))

jsonedit(x, mode = 'view') %>% onRender("function(el,x,data) {this.expandAll();}")

shinyApp(
  ui = shinyUI(
    fluidPage(
      jsoneditOutput( "jsed" )
    )
  ),
  server = function(input, output){
    output$jsed <- renderJsonedit({
      jsonedit(x, mode = 'view') %>% onRender("function(el,x,data) {this.expandAll();}")
    })
  }
)
like image 512
pseudospin Avatar asked Aug 30 '26 20:08

pseudospin


1 Answers

jsonedit(x, mode = 'view') %>% 
  onRender("function(el,x,data) {this.editor.expandAll();}")
like image 97
Stéphane Laurent Avatar answered Sep 01 '26 10:09

Stéphane Laurent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!