Display other output before input

Asked

Viewed 45 times

-1

I’m creating a code to analyze the activities sent by the students of a school. The idea is to make each activity appear, one by one in my notebook and through an input I trigger other codes, according to the intended action for the activity analyzed.

It turns out, when viewed in the same cell, I can either view the PDF or the input.

My intention was to be able to visualize both things, because the answer to the input depends on the information described in the pdf.

Here is an example of what happens when I have not yet entered the input. The PDF window is normally displayed: inserir a descrição da imagem aqui



Already here, an example of what happens when I input the input. jupyter ignores the PDF display and jumps to the text box: inserir a descrição da imagem aqui

Is there any way I can display both elements in the same cell?

1 answer

0

Whereas its PDF function is like that one, then it would be possible to merge the opening PDF HTML with an HTML input. For example:

class PDF(object):
    def __init__(self, pdf, size=(200,200)):
        self.pdf = pdf
        self.size = size

    def _repr_html_(self):
        return f"<iframe src={self.pdf} width={self.size[0]} height={self.size[1]}></iframe>"+'''<br/>
            Selecione uma opção abaixo:<br/>
            1 - Devolver para estudante.<br/>
            2 - Encaminhar para Coordenador.<br/>
            3 - Indeferir.<br/>
            <input type="text" 
            onkeydown="if (event.keyCode == 13) {
                alert(this.value)
            }">
        '''

    def _repr_latex_(self):
        return r'\includegraphics[width=1.0\textwidth]{{{0}}}'.format(self.pdf)

a = PDF('hat.pdf',size=(800,200))

So when a is called in another block it will not only return the PDF, but also return a text input. Inside the input, when the key Enter (code 13) is pressed, I put the function of alert Javascript (JS) that could be replaced by the desired function, if it was solvable in JS.

If the function should return some value to Python, I know that the command would be something like IPython.notebook.kernel.execute("motivo="+this.value), but I couldn’t make it work in that context.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.