diff --git a/doc/index.rst b/doc/index.rst index cbd20533..5f524ce3 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -1,10 +1,6 @@ Lux: A Python API for Intelligent Visual Discovery ==================================================== -.. .. image:: https://raw.githubusercontent.com/lux-org/lux-resources/master/logo.png -.. :width: 400 -.. :alt: Lux Logo - Lux is a Python library that makes data science easier by automating certain aspects of the data exploration process. Lux is designed to facilitate faster experimentation with data, even when the user does not have a clear idea of what they are looking for. Lux is integrated with an `interactive Jupyter widget `_ that allows users to quickly browse through large collections of data directly within their Jupyter notebooks. This website contains pages that overview of the basic and advanced functionalities supported in Lux. If you prefer to follow along these tutorial on your own in a Jupyter notebook, you can clone `this repo `_ to download the `tutorials `_ or launch a live notebook `via Binder `_ to try it out. diff --git a/lux/core/frame.py b/lux/core/frame.py index d4e950bc..7eab2ed1 100644 --- a/lux/core/frame.py +++ b/lux/core/frame.py @@ -66,6 +66,7 @@ def __init__(self, *args, **kw): self._saved_export = None self._current_vis = [] self._prev = None + self._widget = None super(LuxDataFrame, self).__init__(*args, **kw) self.table_name = "" @@ -514,7 +515,7 @@ def exported(self) -> Union[Dict[str, VisList], VisList]: When all the exported vis is from the same tab, return a VisList of selected visualizations. -> VisList(v1, v2...) When the exported vis is from the different tabs, return a dictionary with the action name as key and selected visualizations in the VisList. -> {"Enhance": VisList(v1, v2...), "Filter": VisList(v5, v7...), ..} """ - if not hasattr(self, "_widget"): + if self.widget is None: warnings.warn( "\nNo widget attached to the dataframe." "Please assign dataframe to an output variable.\n" @@ -791,6 +792,92 @@ def rec_to_JSON(recs): del rec_lst[idx]["collection"] return rec_lst + def save_as_html(self, filename: str = "export.html") -> None: + """ + Save dataframe widget as static HTML file + + Parameters + ---------- + filename : str + Filename for the output HTML file + """ + + if self.widget is None: + self.maintain_metadata() + self.maintain_recs() + + from ipywidgets.embed import embed_data + + data = embed_data(views=[self.widget]) + + import json + + manager_state = json.dumps(data["manager_state"]) + widget_view = json.dumps(data["view_specs"][0]) + + # Separate out header since CSS file conflict with {} notation in Python format strings + header = """ + + + Lux Widget + + + + + + + + + + + """ + html_template = """ + + {header} + + + + + + + + + + + """ + + manager_state = json.dumps(data["manager_state"]) + widget_view = json.dumps(data["view_specs"][0]) + rendered_template = html_template.format( + header=header, manager_state=manager_state, widget_view=widget_view + ) + with open(filename, "w") as fp: + fp.write(rendered_template) + print(f"Saved HTML to {filename}") + # Overridden Pandas Functions def head(self, n: int = 5): self._prev = self