示例#1
0
    def _repr_html_(self):
        """Used to output the HTML representation to a Jupyter notebook.
        When config.notebook.iframe.attribute is "src", this function creates a temporary HTML file
        in `./tmp/profile_[hash].html` and returns an Iframe pointing to that contents.
        When config.notebook.iframe.attribute is "srco", the same HTML is injected in the "srcdoc" attribute of
        the Iframe.

        Notes:
            This constructions solves problems with conflicting stylesheets and navigation links.
        """
        attribute = config["notebook"]["iframe"]["attribute"].get(str)
        if attribute == "src":
            tmp_file = Path("./ipynb_tmp") / self.get_unique_file_name()
            tmp_file.parent.mkdir(exist_ok=True)
            self.to_file(tmp_file)
            from IPython.lib.display import IFrame, display

            display(
                IFrame(
                    str(tmp_file),
                    width=config["notebook"]["iframe"]["width"].get(str),
                    height=config["notebook"]["iframe"]["height"].get(str),
                ))
        elif attribute:
            from IPython.core.display import HTML, display

            iframe = """
                <iframe
                    width="{width}"
                    height="{height}"
                    srcdoc="{src}"
                    frameborder="0"
                    allowfullscreen
                ></iframe>
                """
            iframe = iframe.format(
                width=config["notebook"]["iframe"]["width"].get(str),
                height=config["notebook"]["iframe"]["height"].get(str),
                src=html.escape(self.to_html()),
            )
            display(HTML(iframe))
        else:
            raise ValueError(
                'Iframe Attribute can be "src" or "srcdoc" (current: {}).'.
                format(attribute))
示例#2
0
def get_notebook_iframe_src(profile):
    """Get the IPython IFrame object

    Args:
        profile: The profile report object

    Returns:
        IPython IFrame object.
    """
    tmp_file = Path("./ipynb_tmp") / profile.get_unique_file_name()
    tmp_file.parent.mkdir(exist_ok=True)
    profile.to_file(tmp_file)
    from IPython.lib.display import IFrame

    return IFrame(
        str(tmp_file),
        width=config["notebook"]["iframe"]["width"].get(str),
        height=config["notebook"]["iframe"]["height"].get(str),
    )
示例#3
0
    def _repr_html_(self):
        """Used to output the HTML representation to a Jupyter notebook. This function creates a temporary HTML file
        in `./tmp/profile_[hash].html` and returns an Iframe pointing to that contents.

        Notes:
            This constructions solves problems with conflicting stylesheets and navigation links.
        """
        tmp_file = Path("./ipynb_tmp") / self.get_unique_file_name()
        tmp_file.parent.mkdir(exist_ok=True)
        self.to_file(tmp_file)
        from IPython.lib.display import IFrame
        from IPython.core.display import display

        display(
            IFrame(
                str(tmp_file),
                width=config["notebook"]["iframe"]["width"].get(str),
                height=config["notebook"]["iframe"]["height"].get(str),
            ))
示例#4
0

# ### ** Part 5: CTR data download **

# #### Lab four will explore website click-through data provided by Criteo.  To obtain the data, you must first accept Criteo's data sharing agreement.  Below is the agreement from Criteo.  After you accept the agreement, you can obtain the download URL by right-clicking on the "Download Sample" button and clicking "Copy link address" or "Copy Link Location", depending on your browser.  Paste the URL into the `# TODO` cell below.  The file is 8.4 MB compressed.  The script below will download the file to the virtual machine (VM) and then extract the data.
# #### If running the cell below does not render a webpage, open the [Criteo agreement](http://labs.criteo.com/downloads/2014-kaggle-display-advertising-challenge-dataset/) in a separate browser tab. After you accept the agreement, you can obtain the download URL by right-clicking on the "Download Sample" button and clicking "Copy link address" or "Copy Link Location", depending on your browser.  Paste the URL into the `# TODO` cell below.
# #### Note that the download could take a few minutes, depending upon your connection speed.

# In[56]:

# Run this code to view Criteo's agreement
# Note that some ad blocker software will prevent this IFrame from loading.
# If this happens, open the webpage in a separate tab and follow the instructions from above.
from IPython.lib.display import IFrame

IFrame("http://labs.criteo.com/downloads/2014-kaggle-display-advertising-challenge-dataset/",
       600, 350)


# In[57]:

# TODO: Replace <FILL IN> with appropriate code
# Just replace <FILL IN> with the url for dac_sample.tar.gz
import glob
import os.path
import tarfile
import urllib
import urlparse

# Paste url, url should end with: dac_sample.tar.gz
url = 'http://labs.criteo.com/wp-content/uploads/2015/04/dac_sample.tar.gz'
示例#5
0
 def ui_add_iframe(self, width='100%', height=400):
     iframe = IFrame(self.url(), width=width, height=height)
     display(HTML("<style>.container { width:98% !important; }</style>"))
     display(iframe)
示例#6
0
def erp5PivotTableUI(self, df):
    from IPython.display import IFrame
    template = """
  <!DOCTYPE html>
  <html>
    <head>
      <title>PivotTable.js</title>

      <!-- external libs from cdnjs -->
      <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.css">
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-csv/0.71/jquery.csv-0.71.min.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.js"></script>

      <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/pivottable/2.0.2/pivot.min.css">
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pivottable/2.0.2/pivot.min.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pivottable/2.0.2/d3_renderers.min.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pivottable/2.0.2/c3_renderers.min.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pivottable/2.0.2/export_renderers.min.js"></script>

      <style>
        body {font-family: Verdana;}
        .node {
         border: solid 1px white;
         font: 10px sans-serif;
         line-height: 12px;
         overflow: hidden;
         position: absolute;
         text-indent: 2px;
        }
        .c3-line, .c3-focused {stroke-width: 3px !important;}
        .c3-bar {stroke: white !important; stroke-width: 1;}
        .c3 text { font-size: 12px; color: grey;}
        .tick line {stroke: white;}
        .c3-axis path {stroke: grey;}
        .c3-circle { opacity: 1 !important; }
      </style>
    </head>
    <body>
      <script type="text/javascript">
        $(function(){
          if(window.location != window.parent.location)
            $("<a>", {target:"_blank", href:""})
              .text("[pop out]").prependTo($("body"));

          $("#output").pivotUI( 
            $.csv.toArrays($("#output").text()), 
            { 
              renderers: $.extend(
                $.pivotUtilities.renderers, 
                $.pivotUtilities.c3_renderers, 
                $.pivotUtilities.d3_renderers,
                $.pivotUtilities.export_renderers
                ),
              hiddenAttributes: [""]
            }
          ).show();
         });
      </script>
      <div id="output" style="display: none;">%s</div>
    </body>
  </html>
  """
    html_string = template % df.to_csv()
    from hashlib import sha512
    key = sha512(html_string).hexdigest()
    storeIFrame(self, html_string, key)
    iframe_host = self.REQUEST['HTTP_X_FORWARDED_HOST'].split(',')[0]
    url = "https://%s/erp5/Base_displayPivotTableFrame?key=%s" % (iframe_host,
                                                                  key)
    return IFrame(src=url, width='100%', height='500')
示例#7
0
文件: viewer.py 项目: vermaa1/cyREST
def embedShare(url, width=DEF_WIDTH, height=DEF_HEIGHT):
    from IPython.core.display import display
    from IPython.lib.display import IFrame
    return display(IFrame(url, width, height))