我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用IPython.display.IFrame()。
def view_url_clicked(b): DrilsdownUI.do_display(HTML("<a target=ramadda href=" + b.url + ">" + b.name + "</a>")) display(IFrame(src=b.url, width=800, height=400))
def save_fig(name, root_dir=None, notebook_mode=True, default_overwrite=False, extension='pdf', **savefig_kwargs): if root_dir is None: root_dir = os.getcwd() directory = check_or_create_dir(join_paths(root_dir, FOLDER_NAMINGS['PLOTS_DIR']), notebook_mode=notebook_mode) filename = join_paths(directory, '%s.%s' % (name, extension)) # directory + '/%s.pdf' % name if not default_overwrite and os.path.isfile(filename): # if IPython is not None: # IPython.display.display(tuple(IFrame(filename, width=800, height=600))) # FIXME not working! overwrite = input('A file named %s already exists. Overwrite (Leave string empty for NO!)?' % filename) if not overwrite: print('No changes done.') return plt.savefig(filename, **savefig_kwargs) # print('file saved')
def show(url): return IFrame(url, width=400, height=400) # THE FUNCTION YOU ACTUALLY USE WITH THIS MODULE
def to_notebook(self, path_and_name='temp.html', width=None, height=None): """open viz in notebook cell""" self.to_file(path_and_name) display(IFrame(src=path_and_name, width=self.width if width is None else width, height=self.height if height is None else height))
def plot(url): """Return an IFrame plot""" from IPython.display import IFrame return IFrame(url, width='100%', height=500)
def display(self): self.__render() return IFrame('%s.html'%self.name, width=1000, height=600)
def tilemap(tif, name, overwrite=False, overlay=None,tilelvl=[9,13]): id=hashlib.sha1(name).hexdigest()[:10] if overwrite: os.system('rm -rf %s'%id) os.system('gdal2tiles.py -e -z %d-%d -a 0,0,0 -s epsg:4326 -r bilinear -t "%s" %s -z 8-14 %s'%(tilelvl[0], tilelvl[1], name,tif,id)) with open('%s/leaflet.html'%id) as input: s=input.read() s=s.replace('http://cdn.leafletjs.com','https://cdn.leafletjs.com') s=s.replace('http://{s}.tile.osm.org','https://{s}.tile.openstreetmap.org') addLayer='map.addLayer(lyr);' if overlay: os.system("wget 'https://raw.githubusercontent.com/calvinmetcalf/leaflet-ajax/master/dist/leaflet.ajax.min.js' -O %s/leaflet.ajax.min.js"%id) s=s.replace('leaflet.js"></script>','leaflet.js"></script>\n<script src="leaflet.ajax.min.js"></script>') vectorNewLayers = [] vectorOverlay = [] vectorAdd = [] for vecFile,vecName in overlay: vecId=hashlib.sha1(vecName).hexdigest()[:10] os.system('ogr2ogr -f "geojson" %s/%s.json %s'%(id,vecId,vecFile)) vectorNewLayers.append('var vecLayer%s = new L.GeoJSON.AJAX("%s.json");'%(vecId,vecId)) vectorOverlay.append('"%s":vecLayer%s'%(vecName, vecId)) vectorAdd.append('map.addLayer(vecLayer%s);'%vecId) s=s.replace('// Map','\n'.join(vectorNewLayers)+'\n // Map') s=s.replace('{"Layer": lyr}','{'+','.join(vectorOverlay)+', "Layer": lyr}') addLayer+='\n'.join(vectorAdd) s=s.replace(').addTo(map);',').addTo(map); '+addLayer) with open('%s/leaflet.html'%id,'w') as output: output.write(s) return IFrame('%s/leaflet.html'%id, width='1000',height='600')
def pivot_ui(df, outfile_path = "pivottablejs.html", width="100%", height="500"): # FIXME: we shouldn't hard-code the port here port = 8888 # get_config().NotebookApp.port static_path = 'http://localhost:%s' % port with open(outfile_path, 'w') as outfile: outfile.write(template % {'div': df.to_csv(), 'static': '%s/static' % static_path}) return IFrame(src=outfile_path, width=width, height=height)
def enable_chimera_inline(): """ Enable IPython magic commands to run some Chimera actions Currently supported: - %chimera_export_3D [<model>]: Depicts the Chimera 3D canvas in a WebGL iframe. Requires a headless Chimera build and a Notebook instance. SLOW. - %chimera_run <command>: Runs Chimera commands meant to be input in the GUI command line """ from IPython.display import IFrame from IPython.core.magic import register_line_magic import chimera import Midas @register_line_magic def chimera_export_3D(line): if chimera.viewer.__class__.__name__ == 'NoGuiViewer': print('This magic requires a headless Chimera build. ' 'Check http://www.cgl.ucsf.edu/chimera/download.html#unsupported.', file=sys.stderr) return models = eval(line) if line else [] def html(*models): if models: for m in chimera.openModels.list(): m.display = False chimera.selection.clearCurrent() for model in models: model.display = True chimera.selection.addCurrent(model) chimera.runCommand('focus sel') chimera.viewer.windowSize = 800, 600 path = 'chimera_scene_export.html' Midas.export(filename=path, format='WebGL') return IFrame(path, *[x + 20 for x in chimera.viewer.windowSize]) return html(*models) del chimera_export_3D @register_line_magic def chimera_run(line): if not line: print("Usage: %chimera_run <chimera command>", file=sys.stderr) return chimera.runCommand(line) del chimera_run
def launch_arborist_gui(json_data: str, height=650): """ :param json_data: :param height: :return: """ new_temp_dir = tempfile.mkdtemp() tmp_json = os.path.join(new_temp_dir, 'tmp_json') with open(tmp_json, 'w') as f: f.write(json_data) # Signal created by Javascript to continue work here. done_signal = os.path.join(os.path.dirname(tmp_json), 'DONE') base_url = os.environ.get("ARBORIST_BASE_URL", "/") running_on = '{}transmart-arborist?treefile={}'.format(base_url, os.path.abspath(tmp_json)) display(IFrame(src=running_on, width='100%', height=height)) try: # Wait for the done signal file to be created before breaking the GIL. while not os.path.exists(done_signal): time.sleep(0.1) except KeyboardInterrupt: # This stops the interpreter without showing a stacktrace. pass else: updated_json = None # We've been having issues with a slow file system where the json response was empty # Now we make sure something is sent back. while not updated_json: time.sleep(0.1) with open(tmp_json, 'r') as f: updated_json = f.read() return updated_json finally: shutil.rmtree(new_temp_dir) # Clear output from Jupyter Notebook cell clear_output() print('Cleaning up before closing...')