JohnCoene / javascript-for-r

📚 JavaScript for R CRC Book
https://javascript-for-r.com/
Other
181 stars 46 forks source link

Potential inconsistency between example code and explanation - Chapter 12 section 'As a Package' #37

Open calderonsamuel opened 1 year ago

calderonsamuel commented 1 year ago

Great material! I'm having trouble following this section as I think it might contain an inconsistency between the code and the explanation in this section.

https://github.com/JohnCoene/javascript-for-r/blob/77fd95c7a5c89caf5fca266149cb230cc4a05a4e/4-12-shiny-complete.Rmd#L553-L560

It is not possible to find how the code 1) allows for a dynamically generated id from the R server, and 2) generates a dynamic input name from JS.

I believe this is an unfinished adaptation from this lines:

https://github.com/JohnCoene/javascript-for-r/blob/77fd95c7a5c89caf5fca266149cb230cc4a05a4e/4-12-shiny-complete.Rmd#L379-L386

Looking at some code in your marker package makes me think that the code could look like this:

Shiny.addCustomMessageHandler('classify', function(data){ 
   // Classify from input id
   classifier.classify( 
     document.getElementById(data, (err, results) => { 
       Shiny.setInputValue(data + "_classification:ml5.class", results); 
     } 
   ); 
 });