How to use pixiedust - 10 common examples

To help you get started, we’ve selected a few pixiedust examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pixiedust / pixiedust_node / pixiedust_node / node.py View on Github external
if line:
                    obj = json.loads(line)
                    # if it does and is a pixiedust object
                    if obj and isinstance(obj, dict) and obj['_pixiedust']:
                        if obj['type'] == 'display':
                            pdf = pandas.DataFrame(obj['data'])
                            ShellAccess.pdf = pdf
                            display(pdf)
                        elif obj['type'] == 'print':
                            print(json.dumps(obj['data']))
                        elif obj['type'] == 'store':
                            print('!!! Warning: store is now deprecated - Node.js global variables are automatically propagated to Python !!!')
                            variable = 'pdf'
                            if 'variable' in obj:
                                variable = obj['variable']
                            ShellAccess[variable] = pandas.DataFrame(obj['data'])
                        elif obj['type'] == 'html':
                            IPython.display.display(IPython.display.HTML(obj['data']))
                        elif obj['type'] == 'image':
                            IPython.display.display(IPython.display.HTML('<img src="{0}">'.format(obj['data'])))
                        elif obj['type'] == 'variable':
                            ShellAccess[obj['key']] = obj['value']
                            if self.vw:
                                self.vw.setCache(obj['key'], obj['value'])
                    else:
                        print(line)
            except Exception as e:
                # output the original line when we don't have JSON
                line = line.strip()
                if len(line) &gt; 0:
                    print(line)
github pixiedust / pixiedust_node / pixiedust_node / nodestdreader.py View on Github external
try:
                if line:
                  obj = json.loads(line)
            except Exception as e:
                # output the original line when we don't have JSON
                line = line.strip()
                if len(line) &gt; 0:
                    print(line)

            try:

                # if it does and is a pixiedust object
                if obj and obj['_pixiedust']: 
                    if obj['type'] == 'display':
                        pdf = pandas.DataFrame(obj['data'])
                        ShellAccess.pdf = pdf
                        display(pdf)
                    elif obj['type'] == 'print':
                        print(json.dumps(obj['data']))
                    elif obj['type'] == 'store':
                        variable = 'pdf'
                        if 'variable' in obj:
                            variable = obj['variable']
                        ShellAccess[variable] = pandas.DataFrame(obj['data'])
                    elif obj['type'] == 'html':
                        IPython.display.display(IPython.display.HTML(obj['data']))
                    elif obj['type'] == 'image':
                        IPython.display.display(IPython.display.HTML('<img src="{0}">'.format(obj['data'])))
  
            except Exception as e:
                print(line)
                print(e)
github pixiedust / pixiedust_node / pixiedust_node / nodestdreader.py View on Github external
try:

                # if it does and is a pixiedust object
                if obj and obj['_pixiedust']: 
                    if obj['type'] == 'display':
                        pdf = pandas.DataFrame(obj['data'])
                        ShellAccess.pdf = pdf
                        display(pdf)
                    elif obj['type'] == 'print':
                        print(json.dumps(obj['data']))
                    elif obj['type'] == 'store':
                        variable = 'pdf'
                        if 'variable' in obj:
                            variable = obj['variable']
                        ShellAccess[variable] = pandas.DataFrame(obj['data'])
                    elif obj['type'] == 'html':
                        IPython.display.display(IPython.display.HTML(obj['data']))
                    elif obj['type'] == 'image':
                        IPython.display.display(IPython.display.HTML('<img src="{0}">'.format(obj['data'])))
  
            except Exception as e:
                print(line)
                print(e)
github pixiedust / pixiedust_node / pixiedust_node / node.py View on Github external
# forever
        while not self._stop_event.is_set():
            # read line from Node's stdout
            line = self.ps.stdout.readline()

            # see if it parses as JSON
            obj = None
            try:
                if line:
                    obj = json.loads(line)
                    # if it does and is a pixiedust object
                    if obj and isinstance(obj, dict) and obj['_pixiedust']:
                        if obj['type'] == 'display':
                            pdf = pandas.DataFrame(obj['data'])
                            ShellAccess.pdf = pdf
                            display(pdf)
                        elif obj['type'] == 'print':
                            print(json.dumps(obj['data']))
                        elif obj['type'] == 'store':
                            print('!!! Warning: store is now deprecated - Node.js global variables are automatically propagated to Python !!!')
                            variable = 'pdf'
                            if 'variable' in obj:
                                variable = obj['variable']
                            ShellAccess[variable] = pandas.DataFrame(obj['data'])
                        elif obj['type'] == 'html':
                            IPython.display.display(IPython.display.HTML(obj['data']))
                        elif obj['type'] == 'image':
                            IPython.display.display(IPython.display.HTML('<img src="{0}">'.format(obj['data'])))
                        elif obj['type'] == 'variable':
                            ShellAccess[obj['key']] = obj['value']
                            if self.vw:
github pixiedust / pixiedust_node / pixiedust_node / __init__.py View on Github external
def __init__(self, shell, node):
        super(PixiedustNodeMagics,self).__init__(shell=shell) 
        display(HTML(
"""
            <div style="margin:10px"> 
            <a href="https://github.com/pixiedust/pixiedust_node"> 
            <img style="float:left;margin-right:10px" src="https://github.com/pixiedust/pixiedust_node/raw/master/docs/_images/pdn_icon32.png"> 
            </a> 
            <span>Pixiedust Node.js</span> 
            </div> 
"""
        ))
        self.n = node
        ShellAccess.npm = Npm()
        ShellAccess.node = self.n
github pixiedust / pixiedust_node / pixiedust_node / __init__.py View on Github external
def __init__(self, shell, node):
        super(PixiedustNodeMagics,self).__init__(shell=shell) 
        display(HTML(
"""
            <div style="margin:10px"> 
            <a href="https://github.com/pixiedust/pixiedust_node"> 
            <img style="float:left;margin-right:10px" src="https://github.com/pixiedust/pixiedust_node/raw/master/docs/_images/pdn_icon32.png"> 
            </a> 
            <span>Pixiedust Node.js</span> 
            </div> 
"""
        ))
        self.n = node
        ShellAccess.npm = Npm()
        ShellAccess.node = self.n
github pixiedust / pixiedust_node / pixiedust_node / npm.py View on Github external
def cmd(self, command, module):
        # create node_modules
        home = Environment.pixiedustHome
        node_home = os.path.join(home,'node')
        node_modules = os.path.join(node_home,'node_modules')
        if not os.path.exists(node_modules):
            os.makedirs(node_modules)

        # create sub-process
        npm_path = self.which('npm')
        args = [npm_path, command, '-s']
        if (module):
            if (isinstance(module, str)):
                args.append(module)
            else:
                args.extend(module)
        print (' '.join(args))
        ps = subprocess.Popen( args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd = node_home)
github pixiedust / pixiedust_node / pixiedust_node / node.py View on Github external
def __init__(self):
        """
        Establishes the Node's home directories and executable paths
        """
        # get the home directory
        home = Environment.pixiedustHome

        # Node home directory
        self.node_home = os.path.join(home, 'node')
        if not os.path.exists(self.node_home):
            os.makedirs(self.node_home)

        # Node modules home directory
        self.node_modules = os.path.join(self.node_home, 'node_modules')
        if not os.path.exists(self.node_modules):
            os.makedirs(self.node_modules)

        self.node_prog = 'node'
        self.npm_prog = 'npm'
        if platform.system() == 'Windows':
            self.node_prog += '.exe'
            self.npm_prog += '.cmd'
github pixiedust / pixiedust_node / pixiedust_node / node.py View on Github external
# forever
        while not self._stop_event.is_set():
            # read line from Node's stdout
            line = self.ps.stdout.readline()

            # see if it parses as JSON
            obj = None
            try:
                if line:
                    obj = json.loads(line)
                    # if it does and is a pixiedust object
                    if obj and isinstance(obj, dict) and obj['_pixiedust']:
                        if obj['type'] == 'display':
                            pdf = pandas.DataFrame(obj['data'])
                            ShellAccess.pdf = pdf
                            display(pdf)
                        elif obj['type'] == 'print':
                            print(json.dumps(obj['data']))
                        elif obj['type'] == 'store':
                            print('!!! Warning: store is now deprecated - Node.js global variables are automatically propagated to Python !!!')
                            variable = 'pdf'
                            if 'variable' in obj:
                                variable = obj['variable']
                            ShellAccess[variable] = pandas.DataFrame(obj['data'])
                        elif obj['type'] == 'html':
                            IPython.display.display(IPython.display.HTML(obj['data']))
                        elif obj['type'] == 'image':
                            IPython.display.display(IPython.display.HTML('<img src="{0}">'.format(obj['data'])))
                        elif obj['type'] == 'variable':
                            ShellAccess[obj['key']] = obj['value']
                            if self.vw:
                                self.vw.setCache(obj['key'], obj['value'])
github pixiedust / pixiegateway / pixiegateway / handlers / handlers.py View on Github external
def get(self):
        from pixiedust.display.display import Display
        class PixieDustDisplay(Display):
            def doRender(self, handlerId):
                pass
        self.set_header('Content-Type', 'text/javascript' if self.loadjs else 'text/css')
        disp = PixieDustDisplay({"gateway":"true"}, None)
        disp.callerText = "display(None)"
        self.write(disp.renderTemplate("pixiedust.js" if self.loadjs else "pixiedust.css"))
        self.finish()