-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to spawn code notebooks from cBioPortal queries (#4856)
* Add ability to spawn juypyeter lite code notebooks populated with data from Oncoprint
- Loading branch information
1 parent
aab9c4c
commit 50adab2
Showing
8 changed files
with
397 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
## For using the notebook and its contents: | ||
|
||
1. The code for the Jupyterlite extension and the environment can be accessed from [here](https://github.com/cBioPortal/cbio-jupyter). | ||
2. The instructions to use it present in this [file](https://github.com/cBioPortal/cbio-jupyter/blob/main/README.md) |
148 changes: 148 additions & 0 deletions
148
src/pages/staticPages/tools/oncoprinter/JupyterNotebookModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import { action, observable } from 'mobx'; | ||
import React from 'react'; | ||
import { | ||
Modal, | ||
Form, | ||
FormControl, | ||
FormGroup, | ||
ControlLabel, | ||
Button, | ||
} from 'react-bootstrap'; | ||
import { buildCBioPortalPageUrl } from 'shared/api/urls'; | ||
|
||
interface FilenameModalProps { | ||
show: boolean; | ||
fileContent: string; | ||
fileName: string; | ||
handleClose: () => void; | ||
} | ||
|
||
interface FilenameModalState { | ||
folderName: string; | ||
validated: boolean; | ||
errorMessage: string; | ||
} | ||
|
||
class JupyterNoteBookModal extends React.Component< | ||
FilenameModalProps, | ||
FilenameModalState | ||
> { | ||
public channel: BroadcastChannel; | ||
|
||
constructor(props: FilenameModalProps) { | ||
super(props); | ||
this.state = { | ||
folderName: '', | ||
validated: false, | ||
errorMessage: '', | ||
}; | ||
this.channel = new BroadcastChannel('jupyter_channel'); | ||
} | ||
|
||
componentDidMount() { | ||
this.setState({ folderName: '' }); | ||
} | ||
|
||
handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
this.setState({ folderName: event.target.value, errorMessage: '' }); | ||
}; | ||
|
||
@action | ||
handleSubmit = (event: React.FormEvent<HTMLFormElement>) => { | ||
event.preventDefault(); | ||
|
||
const { folderName } = this.state; | ||
|
||
if (folderName.trim() === '' || /\s/.test(folderName)) { | ||
this.setState({ | ||
validated: false, | ||
errorMessage: 'Session name cannot be empty or contain spaces', | ||
}); | ||
return; | ||
} | ||
|
||
const { fileContent, fileName } = this.props; | ||
|
||
const data = { | ||
type: 'from-cbioportal-to-jupyterlite', | ||
fileContent: fileContent, | ||
filename: `${fileName}.csv`, | ||
folderName: folderName, | ||
}; | ||
|
||
const jupyterNotebookTool = window.open( | ||
'https://cbio-jupyter.netlify.app/lite/lab/index.html', | ||
'_blank' | ||
); | ||
|
||
if (jupyterNotebookTool) { | ||
const receiveMessage = (event: MessageEvent) => { | ||
if (event.data.type === 'jupyterlite-ready') { | ||
console.log('Now sending the data...'); | ||
jupyterNotebookTool.postMessage(data, '*'); | ||
window.removeEventListener('message', receiveMessage); | ||
this.props.handleClose(); | ||
} | ||
}; | ||
|
||
window.addEventListener('message', receiveMessage); | ||
} | ||
|
||
this.setState({ folderName: '', validated: false, errorMessage: '' }); | ||
// this.props.handleClose(); | ||
}; | ||
|
||
render() { | ||
const { show, handleClose } = this.props; | ||
const { folderName, errorMessage } = this.state; | ||
|
||
return ( | ||
<Modal show={show} onHide={handleClose}> | ||
<Modal.Header closeButton> | ||
<Modal.Title>Enter Session Name</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<Form | ||
onSubmit={e => | ||
this.handleSubmit( | ||
(e as unknown) as React.FormEvent< | ||
HTMLFormElement | ||
> | ||
) | ||
} | ||
> | ||
<FormGroup controlId="formFolderName"> | ||
<ControlLabel className="py-2"> | ||
Session Name | ||
</ControlLabel> | ||
<FormControl | ||
type="text" | ||
placeholder="Enter Session Name" | ||
value={folderName} | ||
onChange={e => | ||
this.handleChange( | ||
(e as unknown) as React.ChangeEvent< | ||
HTMLInputElement | ||
> | ||
) | ||
} | ||
required | ||
/> | ||
{errorMessage && ( | ||
<div style={{ color: 'red' }}> | ||
{errorMessage} | ||
</div> | ||
)} | ||
</FormGroup> | ||
<Modal.Footer> | ||
<Button onClick={handleClose}>Close</Button> | ||
<Button type="submit">Open Jupyter Notebook</Button> | ||
</Modal.Footer> | ||
</Form> | ||
</Modal.Body> | ||
</Modal> | ||
); | ||
} | ||
} | ||
|
||
export default JupyterNoteBookModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.