Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure R graphics in notebook live in correct place #11249

Closed
kcrisman opened this issue Apr 25, 2011 · 7 comments
Closed

Make sure R graphics in notebook live in correct place #11249

kcrisman opened this issue Apr 25, 2011 · 7 comments

Comments

@kcrisman
Copy link
Member

Currently the following can happen in the notebook.

Here is what happens.  Somehow it first is given a temp name like .Rplot001.png-0TJi, which shows up as a link, and then you click on the link and nothing useful happens.  But then I go to 

cd .sage/sage_notebook.sagenb/home/admin/106/cells/38/ 

(or whatever cell you are in) and I see

ls
Rplot001.png

and that is a normal plot.  So somehow the temp name is funky when displayed.

This should be fixed so that the link is to a real file. Somehow there is something added to the filename.

This is related to, but not the same as #8868, which is about making R graphics always work; this is about making them work better when they already work.

CC: @kcrisman @jhpalmieri

Component: notebook

Keywords: r-project

Issue created by migration from https://trac.sagemath.org/ticket/11249

@kcrisman
Copy link
Member Author

comment:1

Ah, I finally tracked it down. In sagenb/notebook/cell.py:

    def files_html(self, out):
        """
        Returns HTML to display the files in this compute cell's
        directory.

        INPUT:

        - ``out`` - a string; files to exclude.  To exclude bar, foo,
          ..., use the format ``'cell://bar cell://foo ...'``

        OUTPUT:

        - a string

        EXAMPLES::

            sage: nb = sagenb.notebook.notebook.Notebook(tmp_dir()+'.sagenb')
            sage: nb.add_user('sage','sage','sage@sagemath.org',force=True)
            sage: W = nb.create_new_worksheet('Test', 'sage')
            sage: C = sagenb.notebook.cell.Cell(0, 'plot(sin(x),0,5)', '', W)
            sage: C.evaluate()
            sage: W.check_comp(wait=9999)     # random output -- depends on computer speed
            ('d', Cell 0; in=plot(sin(x),0,5), out=
            <html><font color='black'><img src='cell://sage0.png'></font></html>
            <BLANKLINE>
            )
            sage: C.files_html('')     # random output -- depends on computer speed
            '<img src="/home/sage/0/cells/0/sage0.png?...">'
            sage: W.quit()
            sage: nb.delete()
        """
        import time
        D = self.files()
        D.sort()
        if len(D) == 0:
            return ''
        images = []
        files  = []

        from worksheet import CODE_PY
        # The question mark trick here is so that images will be reloaded when
        # the async request requests the output text for a computation.
        # This is inspired by http://www.irt.org/script/416.htm/.
        for F in D:
            if os.path.split(F)[-1] == CODE_PY or 'cell://%s'%F in out:
                continue
            url = os.path.join(self.url_to_self(), F)
            if F.endswith('.png') or F.endswith('.bmp') or \
                    F.endswith('.jpg') or F.endswith('.gif'):
                images.append('<img src="%s?%d">'%(url, time.time()))


So that is where the extra little thing comes from.  Somehow we'll have to circumvent that.   Then 


    def update_html_output(self, output=''):
        """
        Updates this compute cell's the file list with HTML-style
        links or embeddings.
        """
        if self.is_interactive_cell():
            self.__out_html = u""
        else:
            self.__out_html = self.files_html(output)

@kcrisman
Copy link
Member Author

comment:2

Nope, this isn't it, though close. Maybe? But time.time() isn't doing the appending. Where is this coming from?

@kcrisman
Copy link
Member Author

comment:3

Well, but it's not far away...

                                <div class="cell_output_html_wrap"
                                     id="cell_output_html_38">
                                    <img src="/home/admin/106/cells/38/Rplot001.png?1303999010"><a target="_new" href="/home/admin/106/cells/38/.Rplot001.png-0TJi" class="file_link">.Rplot001.png-0TJi</a>

And I think I know where that extra thing comes from. R must create a brief temp file, which is found by the notebook cell in files_html() in sagenb/notebook/cell.py:


            else:
                link_text = str(F)
                if len(link_text) > 40:
                    link_text = link_text[:10] + '...' + link_text[-20:]
                files.append('<a target="_new" href="%s" class="file_link">%s</a>'%(url, link_text))

And this only happens every other time I re-evaluate the cell... Aha! So that means the old file is being moved to a temporary site, and that is being caught. But it quickly is eaten up before I can catch it. Wanna bet? But I haven't been able to catch it, not even with

while True
do
    ls
    sleep .1
done

@kcrisman
Copy link
Member Author

Changed keywords from none to r-project

@fchapoton
Copy link
Contributor

comment:5

yet another ancient ticket about deprecated sagenb, can we close ?

@jhpalmieri
Copy link
Member

comment:6

Yes.

@fchapoton
Copy link
Contributor

comment:7

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants