zachcp / chemdoodle

htmlwidgets for chemdoodle web components
http://zachcp.github.io/chemdoodle/
18 stars 9 forks source link

Example Shiny app with chemsketcher? #4

Closed iainmwallace closed 8 years ago

iainmwallace commented 8 years ago

Would it be possible to get a minimal shiny app example with the new chemsketcher functionality? It is not clear to me how to migrate the gadget to a shiny app.

When I try the code below which I thought was the correct way I get a "ERROR: unused argument (all_files = FALSE)" error.

--ui.R--- library(shiny) library(chemdoodle)

mol=NULL

fluidPage(
chemdoodle_sketcherOutput("sketcher"), actionButton("done", "Go!") )

---server.R---- library(shiny) library(chemdoodle)

shinyServer(function(input, output, session) {

output$sketcher <-renderChemdoodle({ chemdoodle_sketcher(mol=NULL)} )

})

Thanks

Iain

iainmwallace commented 8 years ago

@zachcp, @timelyportfolio any suggestions on how to create a minimal shiny app?

How does one make the 'mol' that is created by the sketcher in the UI tags$script function available in the server.R file so that it can be used to create a smiles string?

tags$script(' document.getElementById("done").onclick = function() { var mol = sketcher.getMolecule(); var jsonmol = new ChemDoodle.io.JSONInterpreter().molTo(mol); Shiny.onInputChange("moleculedata", jsonmol);};') )

Thanks!

TomasHovorka commented 8 years ago

Hi @iainmwallace , not that I thought I would be able to help you, but I tried to run the above script. I have succesfully build chemdoodle (and got the newest versions of rcdk(libs) packages) and e.g. chemdoodle_sketcher(mol=NULL) works (opens the sketcher). But when trying to load the above app I got:

Listening on http://127.0.0.1:6760
Warning in file(con, "r") :
  file("") only supports open = "w+" and open = "w+b": using the former
Warning: Error in structure: object 'chemdoodleOutput' not found
Stack trace (innermost first):
    44: structure
    43: shiny::markRenderFunction
    42: shinyRenderWidget
    41: renderChemdoodle [/Users/hovorkat/Documents/Projects/chemdoodle/R/chemdoodle_viewer.R#113]
    40: server [/Users/hovorkat/Documents/Projects/chemdoodle/app/server.R#6]
     1: runApp
Error in structure(renderFunc, class = c("shiny.render.function", "function"),  : 
  object 'chemdoodleOutput' not found

Any Idea what I am missing? thanks tomas

iainmwallace commented 8 years ago

@TomasHovorka I get the same error. Not sure what the issue is as "chemdoodle_sketcherOutput" is in the chemdoodle_sketcher.R file

@timelyportfolio @zachcp Any ideas on how to fix this?

zachcp commented 8 years ago

@iainmwallace @TomasHovorka

i've been swamped. I think i can set this up this weekend. thanks, zach cp

iainmwallace commented 8 years ago

That would be great, thanks @zachcp

zachcp commented 8 years ago

@iainmwallace @TomasHovorka

i put together a very minimal shiny example. to run it pull the latest and do:

shiny::runApp(appDir = "examples/minimalshinyapp/")

please let me know if there are any issues or if there are improvements you can think of.

zcp

zachcp commented 8 years ago

i'm going to close this. if theres an issueon your end we can reopen.

iainmwallace commented 8 years ago

Works great for me!

Direct publishing to rstudio connect. https://beta.rstudioconnect.com/iwallace/chemdoodle_example/

Interestingly, the tag script retrieving the molecule from the sketcher has to be at near the end of the a generated html file