Giter VIP home page Giter VIP logo

ipymaterialui's Introduction

ipymaterialui

Version Version Conda Version

Jupyter Widgets based on Material-UI which implement Google's Material Design Spec with React.

Installation

Prerequisites: https://ipywidgets.readthedocs.io/en/stable/user_install.html

To install use pip:

$ pip install ipymaterialui
$ jupyter labextension install jupyter-materialui             # for lab

For a development installation (requires npm),

$ git clone https://github.com/maartenbreddels/ipymaterialui.git
$ cd ipymaterialui
$ pip install -e .
$ jupyter nbextension install --py --symlink --sys-prefix ipymaterialui
$ jupyter nbextension enable --py --sys-prefix ipymaterialui
$ jupyter labextension install ./js

Usage

For examples see the example notebook.

The Material-UI documentation can be used to find all available components and attributes (on the left side bar). Click the <> icon to see the source code of the examples. Scroll to the bottom of the page to access a link to the API of the component. Ipymaterialui tries to stay close to the React and Material-UI API, but the syntax is different:

Description Material-UI ipymaterialui
1 Components are classes instead of HTML <Button .../> Button(...)
2 Child components and text are defined in the children traitlet <Button>text <Icon .../></Button> Button(children=['text', Icon(...)])
3 Flag attributes require a boolean value <Container fixed ... Container(fixed=True ...
4 Attributes are snake_case <Button fullWidth .. Button(full_width=True ...
5 No onChange handler necessary, use observe. Note that the main value is not always value like in ipywidgets (e.g. checked or selected) <Switch onChange="..." mySwitch.checked
6 Event listeners are defined with on_event <Button onClick={someMethod}' ... button.on_event('onClick', some_method)
def some_method(widget, event, data):
7 Regular HTML tags can made with the Html class <div>...</div> Html(tag='div', children=[...])
8 The attributes class and style need to be suffixed with an underscore <Button class="mr-3" style="..." > Button(class_='mr-3', style_={...})
9 Icon uses the lowercase name from Material icons <AlarmOnIcon .../> Icon(children='alarm_on' ...)

Examples

Aspect 1, 2, 3, 4, 6, 8 and 9

This example demonstrates aspect 1, 2, 3, 4, 6, 8 and 9 of the table above.

materiaui-button

React/Material-UI

const useStyles = makeStyles(theme => ({                      (8)
    alarmOnIcon: {
        marginRight: theme.spacing(1),
    },
}));

export default function MyButton() {
    const classes = useStyles();                              (8)
    const [btnText, setBtnText] = React.useState('Primary');  (6)

    function someMethod() {                                   (6)
        setBtnText(() => new Date().toLocaleTimeString());
    }

    return (
        (1)                                         (3)(4)      (6)          
        <Button variant="contained" color="primary" centerRipple onClick={someMethod}>
            (2)(9)       (8)
            <AlarmOnIcon className={classes.alarmOnIcon}/>
            {btnText}
        </Button>
    );
}

ipymaterialui

import ipymaterialui as mui
import datetime
             (1)                                          (3)(4)              (2)
button = mui.Button(variant='contained', color='primary', center_ripple=True, children=[
             (8)                                      (9)
    mui.Icon(style_={'marginRight': '8px'}, children='alarm_on'),
    'Primary'
])

def some_method(widget, event, data):                 (6)
    time = datetime.datetime.now().strftime("%X")
    button.children = [button.children[0], time]

button.on_event('onClick', some_method)               (6)
button

Aspect 5

This example demonstrates aspect 5 of the table above.

materiaui-switch

React/Material-UI

export default function MySwitch() {
    const [state, setState] = React.useState(true);

    const handleChange = event => {
        setState(event.target.checked);
    };
    
    return (
        <Switch
            checked={state}
            onChange={handleChange}
        />
    );
}

ipymaterialui

import ipymaterialui as mui

mui.Switch(checked=True)

Aspect 7

This example demonstrates aspect 7 of the table above.

React/Material-UI

export default function MyHtml() {
    return (
        <div>some HTML</div>
    );
}

ipymaterialui

import ipymaterialui as mui

mui.Html(tag='div', children='some HTML')

ipymaterialui's People

Contributors

astrofrog avatar maartenbreddels avatar mariobuikhuizen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ipymaterialui's Issues

Cannot pip install on Windows

For some reason, glue-jupyter is pulling this package and it fails to install on Windows.

  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\PL\AppData\Local\Temp\pip-install-l5fbenxu\ipymaterialui\setup.py", line 176, in <module>
      setup(**setup_args)
    File "C:\Users\PL\Miniconda3\envs\py37\lib\site-packages\setuptools\__init__.py", line 145, in setup
      return distutils.core.setup(**attrs)
    File "C:\Users\PL\Miniconda3\envs\py37\lib\distutils\core.py", line 148, in setup
      dist.run_commands()
    File "C:\Users\PL\Miniconda3\envs\py37\lib\distutils\dist.py", line 966, in run_commands
      self.run_command(cmd)
    File "C:\Users\PL\Miniconda3\envs\py37\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\PL\Miniconda3\envs\py37\lib\site-packages\wheel\bdist_wheel.py", line 228, in run
      self.run_command('install')
    File "C:\Users\PL\Miniconda3\envs\py37\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "C:\Users\PL\Miniconda3\envs\py37\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\PL\Miniconda3\envs\py37\lib\site-packages\setuptools\command\install.py", line 61, in run
      return orig.install.run(self)
    File "C:\Users\PL\Miniconda3\envs\py37\lib\distutils\command\install.py", line 557, in run
      self.run_command(cmd_name)
    File "C:\Users\PL\Miniconda3\envs\py37\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "C:\Users\PL\Miniconda3\envs\py37\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\PL\Miniconda3\envs\py37\lib\distutils\command\install_data.py", line 56, in run
      dir = convert_path(f[0])
    File "C:\Users\PL\Miniconda3\envs\py37\lib\distutils\util.py", line 112, in convert_path
      raise ValueError("path '%s' cannot end with '/'" % pathname)
  ValueError: path 'etc/jupyter/nbconfig/notebook.d/' cannot end with '/'
  ----------------------------------------

Error displaying widget: model not found

As the title suggests, I can't seem to be able to display the widgets on Jupyter lab.

Here is the screenshot of error messages produced in the console.
image

Here is my Jupyter build.
image

Define python_requires in setup.py

python_requires should be defined in setup.py to avoid accidentally installing it on older Python versions. It looks like Python 3.6 is required currently.

serve static files

Hi Maarten,

Wow, very cool lib!
Looks like a there's a small issue wrt serving static files however ( eg http://localhost:8888/static/dist/jupyter-materialui.js?v=20181126120611 404's )

I could look into this, but haven't got the pretense to be that knowledgable in the jupyter sphere; this might be resolved by a custom handler. Any comments about the suggested approach? I'm curious how you are serving the static files.

Perfect fit / exciting perspective for flask-ipywidgets ๐Ÿน btw

React component are not unmounted on remove

In the following screenshot, I executed twice the cell displaying the chip. On the React component tree on the right, you can see that the first component has not been unmounted.

image

Loading widget... with jupyter-lab 2.0

Running the example notebook (https://github.com/maartenbreddels/ipymaterialui/blob/master/Core%20examples.ipynb)
in jupyter-lab 2.0, I get a stalled Loading widget... message after cell 4.

Everything seems to work nicely in jupyter notebook and in voila.

Already after cell 3, inspect shows the following:
inspect_ipymaterialui_jupyterlab

My installation:
Ubuntu 18.04,

JupyterLab v2.0.1
Known labextensions:
   app dir: /home/mh/anaconda3/envs/openbabelenv/share/jupyter/lab
        @jupyter-voila/jupyterlab-preview v1.1.0  enabled  OK
        @jupyter-widgets/base v3.0.0  enabled  OK
        @jupyter-widgets/jupyterlab-manager v2.0.0  enabled  OK
        ipysheet v0.4.4  enabled  OK
        ipyvolume v0.5.2  enabled  OK
        jupyter-materialui v0.1.4  enabled  OK
...
$ conda list
...
ipykernel                 5.2.1            py38h23f93f0_0    conda-forge
ipymaterialui             0.1.4                      py_0    conda-forge
ipympl                    0.5.3                      py_0    conda-forge
ipysheet                  0.4.3                      py_1    conda-forge
ipython                   7.14.0           py38h32f6830_0    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
ipywidgets                7.5.1                      py_0  
...
jupyter                   1.0.0                      py_2    conda-forge
jupyter_client            6.1.3                      py_0    conda-forge
jupyter_console           6.1.0                      py_1    conda-forge
jupyter_core              4.6.3            py38h32f6830_1    conda-forge
jupyter_server            0.1.1                    py38_0    conda-forge
jupyterlab                2.0.1                      py_0    conda-forge
jupyterlab-widget-ketcher 0.1.2                    pypi_0    pypi
jupyterlab_pygments       0.1.1              pyh9f0ad1d_0    conda-forge
jupyterlab_server         1.1.4                      py_0    conda-forge
...
nodejs                    13.9.0               h10a4023_0    conda-forge
...
voila                     0.1.21                     py_0    conda-forge
...

Possibly related to #12 .

Failure to install for Jupyter Lab

I tried going inside the js folder and running

jupyter labextension install .

but I got the error:

ERROR in ./node_modules/jupyter-materialui/lib/react-widget.js 22:8
Module parse failed: Unexpected token (22:8)
You may need an appropriate loader to handle this file type.
| function FontSizeTheme(props) {
|     return (
>         <MuiThemeProvider theme={theme}>
|             <Typography component="span">{props.children}</Typography>
|         </MuiThemeProvider>
 @ ./node_modules/jupyter-materialui/lib/index.js 3:0-31 3:0-31
 @ ./node_modules/jupyter-materialui/lib/labplugin.js
 @ ./build/index.out.js
 @ multi whatwg-fetch ./build/index.out.js

ERROR in ./node_modules/jupyter-materialui/lib/core.js 35:19
Module parse failed: Unexpected token (35:19)
You may need an appropriate loader to handle this file type.
|         render() {
|             let { model, ...props } = this.stateProps();
>             return <Component {...props}>{props.children}</Component>
|         }
|     }
 @ ./node_modules/jupyter-materialui/lib/index.js 2:0-23 2:0-23
 @ ./node_modules/jupyter-materialui/lib/labplugin.js
 @ ./build/index.out.js
 @ multi whatwg-fetch ./build/index.out.js

Widgets doesn't fully integrate with jupyterlab dark theme.

I'm using ubuntu with ipymaterialui version 0.1.4.
When switching to jupyter lab dark theme, some widgets didn't changed their themes:
screenshot
While others wrongly changed:
screenshot_1
While others changed partially:
screenshot_3
this last one is strangely unuxpected, because the secondary text attribute got darker then in default theme:
screenshot_4
I don't know much about MaterialUI, much less ipymaterialui, but I looked for the Theme Provider component and I couldn't find it. I also figured out the color attribute is present in some widgets, while in others is not.
I really liked the ipymaterialui package and found that the widgets looks very nice. I'd like to know if I am missing something or if there is a way to change the themes for all widgets in the document.
I also tried the following without success:

%%javascript
document.body.classList.add('theme-dark')

Thanks in advance!

Project dead?

Guessing this project has gone dead? Any desire to bring it back to life/forks?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.