library(shiny)
library(nglShinyS4)
library(htmlwidgets)
#----------------------------------------------------------------------------------------------------
ngl <- NglWidget("1crn", "nglDemoDiv")
#----------------------------------------------------------------------------------------------------
ui = shinyUI(fluidPage(
tags$head(
tags$style("#nglDemoDiv{height:98vh !important;}"),
tags$link(rel="icon", href="data:;base64,iVBORw0KGgo=")
),
sidebarLayout(
sidebarPanel(
actionButton("fitButton", "Fit"),
hr(),
width=3
),
mainPanel(
shinyOutput(ngl),
width=9
)
) # sidebarLayout
))
#----------------------------------------------------------------------------------------------------
server = function(input, output, session) {
observeEvent(input$fitButton, {
session$sendCustomMessage(type="fit", message=list())
})
observeEvent(input$clearRepresentationsButton, {
session$sendCustomMessage(type="removeAllRepresentations", message=list())
#updateSelectInput(session, "representationSelector", label=NULL, choices=NULL, selected=defaultRepresentation)
#updateSelectInput(session, "colorSchemeSelector", label=NULL, choices=NULL, selected=defaultColorScheme)
})
observeEvent(input$pdbSelector, {
choice = input$pdbSelector
printf("pdb: %s", choice)
session$sendCustomMessage(type="setPDB", message=list(choice))
updateSelectInput(session, "pdbSelector", label=NULL, choices=NULL, selected=choice)
})
observeEvent(input$representationSelector, {
choice = input$representationSelector;
printf("rep: %s", choice)
session$sendCustomMessage(type="setRepresentation", message=list(choice))
updateSelectInput(session, "representationSelector", label=NULL, choices=NULL, selected=choice)
})
observeEvent(input$colorSchemeSelector, {
choice = input$colorSchemeSelector;
printf("colorScheme: %s", choice)
session$sendCustomMessage(type="setColorScheme", message=list(choice))
updateSelectInput(session, "colorSchemeSelector", label=NULL, choices=NULL, selected=choice)
})
output$value <- renderPrint({ input$action})
#options <- list(pdbID="1pcr")
#options <- list(pdbID="3kvk")
options <- list(pdbID="1crn")
#options <- list(pdbID="1rqk")
output$nglShiny <- renderWidget(ngl)
} # server
#----------------------------------------------------------------------------------------------------
port <- 11111
browseURL(sprintf("http://localhost:%d", port))
runApp(shinyApp(ui=ui, server=server), port=port)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.