Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: instance.resize is not a function #17

Closed
Tixierae opened this issue Mar 13, 2018 · 2 comments
Closed

Uncaught TypeError: instance.resize is not a function #17

Tixierae opened this issue Mar 13, 2018 · 2 comments

Comments

@Tixierae
Copy link

Tixierae commented Mar 13, 2018

Minimal reproducible example:

library(shiny)
library(C3) # install via devtools::install_github("tixierae/shinyJsTutorials/tutorials/materials2/C3")

server = function(input,output) {
    my_df = reactive({
        input$button
        my_df = list(a=runif(1,0,100),b=runif(1,0,100),c=runif(1,0,100))
        list(my_df=my_df)
    })
    output$my_pie1 = renderC3Pie({
        C3Pie(value = my_df()$my_df)
    })
}
ui = shinyUI(
    navbarPage(id="main", position = "fixed-top", title=NULL, inverse=T, selected="tab1",
        tabPanel("tab1",
            fluidRow(br(),br(),br(),
                actionButton("button", "Draw!"),
                C3PieOutput("my_pie1")
            )
        ),
        tabPanel("tab2",
            fluidRow(br(),br(),br(),
            )
        )
    )
)
shinyApp(ui=ui, server=server)

Procedure to reproduce the error (happens at least on Chrome and Firefox):

  • go to 'tab2'
  • generously zoom in or out
  • go back to 'tab1'. The app is now frozen.

Inspect on Chrome shows:

Uncaught TypeError: instance.resize is not a function
    at Object.resize (htmlwidgets.js:822)
    at exports.OutputBinding.shinyBinding.resize (htmlwidgets.js:526)
    at output_binding_adapter.js:12
    at OutputBindingAdapter.onResize (utils.js:114)
    at HTMLDivElement.<anonymous> (init_shiny.js:305)
    at Function.each (jquery.min.js:2)
    at n.fn.init.each (jquery.min.js:2)
    at j (init_shiny.js:298)
    at Debouncer.$invoke (input_rate.js:56)
    at Debouncer.immediateCall (input_rate.js:44)

I'm working with the dev version of htmlwidgets (installed from GitHub).
In my fork of C3, I just modified the colors of the pie chart.

I'm not sure whether this has to do with the htmlwidgets package or C3.

@timelyportfolio
Copy link

htmlwidgets require a resize method which can be seen in image but unfortunately is not included at the end of the tutorial. While the resize can be empty (do nothing), it still must exist. To fix, add

...
      // update the data
      chart.load({
        // new data
        json  : x.dataset,

        // new colors
        colors: x.colors,

        // remove data we no longer need (if any)
        unload: diff,

        // set types
        types : x.types
      });
    },
    resize: function(width, height) {
      // this will vary based on the JavaScript library
      // in the case of C3 we are fortunate that there is a resize method
      //  http://c3js.org/samples/api_resize.html
      chart.resize({height:height, width:width})
    }
   };
}});

There is another example in this article. Hope it helps.

@Tixierae
Copy link
Author

That solved it! Thank you so much for the prompt and efficient help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants