Opened 11 years ago

Closed 2 years ago

#11249 closed defect (invalid)

Make sure R graphics in notebook live in correct place

Reported by: kcrisman Owned by: jason, mpatel, was
Priority: minor Milestone: sage-duplicate/invalid/wontfix
Component: notebook Keywords: r-project
Cc: kcrisman, jhpalmieri Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

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.

Change History (7)

comment:1 Changed 11 years ago by kcrisman

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)

comment:2 Changed 11 years ago by kcrisman

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

comment:3 Changed 11 years ago by kcrisman

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

comment:4 Changed 11 years ago by kcrisman

  • Keywords r-project added

comment:5 Changed 2 years ago by chapoton

  • Cc kcrisman jhpalmieri added
  • Milestone set to sage-duplicate/invalid/wontfix
  • Status changed from new to needs_review

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

comment:6 Changed 2 years ago by jhpalmieri

  • Status changed from needs_review to positive_review

Yes.

comment:7 Changed 2 years ago by chapoton

  • Resolution set to invalid
  • Status changed from positive_review to closed

thx

Note: See TracTickets for help on using tickets.