zachcp / chemdoodle

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

Chemdoodle viewer in Shiny #9

Closed laylagerami closed 3 years ago

laylagerami commented 3 years ago

Hi, thanks for this great R package.

Trying to get the Chemdoodle viewer to work, this is what I have so far but I get the error

Error in shinyRenderWidget(expr, chemdoodleOutput, env, quoted = TRUE) : object 'chemdoodleOutput' not found

I can see from the renderChemdoodle function that it expects "expr" and "chemdoodleOutput", but it's not clear to me how I should define these? code:

library(shiny)
library(chemdoodle)
library(htmlwidgets)

ui <- fluidPage(

    # Application title
    titlePanel("Testing chemdoodle sketcher"),
       chemdoodle_viewerOutput("chemdoodle")
)

server <- function(input, output) {
    output$chemdoodle = renderChemdoodle(
        chemdoodle_viewer("c1ccccc1")
    )

}

# Run the application 
shinyApp(ui = ui, server = server)

I then tried to create a new function called renderChemdoodle_viewer

function (expr, env = parent.frame(), quoted = FALSE) 
{
    if (!quoted) {
        expr <- substitute(expr)
    }
    shinyRenderWidget(expr, chemdoodle_viewerOutput, env, quoted = TRUE)
}

But in this case, when replacing the "renderChemdoodle" in the above code, the app runs and nothing shows up. Any suggestions on where I am going wrong? Thanks!

zachcp commented 3 years ago

You're welcome.

I think the code I just pushed should solve your problem.