Creating a project context constructor
Every notebook that loads from a data connector requires a hidden cell that defines the project context (hidden cells are not shared). You can automatically inject one by clicking the Find and Add Data button in the toolbar, clicking the Connections tab, finding the connection that you want, and clicking Create DataFrame.
In the following code examples, sc
stands for Spark context, 9389f14a-9e39-4a83-9439-c567568b17e4
represents your project ID (located in the URL), and p-fcc1cc2b7bd74ec779d9e28a89079250590b5d78
represents your project access token. The value of your access token is located in the Settings tab of your project in the Access tokens section.
- Scala syntax
-
// @hidden_cell import com.ibm.analytics.projectNotebookIntegration._ val pc = ProjectUtil.newProjectContext(sc, "9389f14a-9e39-4a83-9439-c567568b17e4", "p-fcc1cc2b7bd74ec779d9e28a89079250590b5d78")
- Python syntax
-
# @hidden_cell from projectnb import ProjectContext, ProjectUtil pc = ProjectContext.ProjectContext(sc, '9389f14a-9e39-4a83-9439-c567568b17e4', 'p-fcc1cc2b7bd74ec779d9e28a89079250590b5d78')
- R syntax
-
# @hidden_cell library(projectnbR) pc <- ProjectContext(sc, "9389f14a-9e39-4a83-9439-c567568b17e4", "p-fcc1cc2b7bd74ec779d9e28a89079250590b5d78")