SimonBiggs / scriptedforms

Quickly create live-update GUIs for Python packages using Markdown and simple HTML elements.
Apache License 2.0
508 stars 34 forks source link

Updated response from database query #244

Closed psychemedia closed 6 years ago

psychemedia commented 6 years ago

I'm trying to display the output of a query made via a <variable-string> and guessed at the following, but whilst a pandas dataframe is displayed as soon as I start to enter something in the text box, it never updates / changes as I continue to type into or make changes to theimage_text string. I had expected to be able to write an interactive query/display?

<section-start>
```python
import pandas
import sqlite3
conn = sqlite3.connect('dummy.sqlite')
pd.DataFrame({'col1':['a','b','ab']}).to_sql('test',conn, if_exists='replace')

image_text ```python pd.read_sql("SELECT * FROM test WHERE col1 LIKE '%{q}%'".format(q=image_text), conn) ```

I tried the `<section-output>` too, which behaved the same, as well as throwing an `q undefined` error until I entered some text (again, not quite what I expected?)
```python from IPython.display import Image import pandas import sqlite3 conn = sqlite3.connect('dummy.sqlite') pd.DataFrame({'col1':['a','b','ab']}).to_sql('test',conn, if_exists='replace') ``` image_text ```python pd.read_sql("SELECT * FROM test WHERE col1 LIKE '%{q}%'".format(q=image_text), conn) ```


What am I missing?

[Hmm... in producing the reproducible example, it works... So must be some issue with my original code...]
SimonBiggs commented 6 years ago

Could you try and run a print in there to see what that query string looks like before you run it?

psychemedia commented 6 years ago

Not sure what it was - I copied from my (working) minimal example and it's fine.. Sorry about that! Scriptedforms is going to be (already is) really powerful and really useful, I think... Thanks

SimonBiggs commented 6 years ago

No need to be sorry. It's encouraging to see it be useful :)

SimonBiggs commented 6 years ago

Also, the section-output issue should be fixed in an upcoming release. It's fixed on the dev release (able to be installed with pip install --pre scriptedforms). There's just a few things I want to iron out before that dev release gets a proper release.

The issue was that the section output was running too early. Essentially it would run before the start section ran, hence the not defined error.

If you're keen, take the dev install for a spin if you keep seeing the issue with the output section.

psychemedia commented 6 years ago

One thing I've noticed - I canlt seem to get the correct path to connect to db in binder? eg https://github.com/psychemedia/openlearn_scripted-form

I note the launch path in the postBuild is /scriptedforms/use/, but I'm not sure how to set an appropriate basepath to the sqlite file in my md file?

psychemedia commented 6 years ago

Re: useful - yes... it will be very:-)

I'm pondering also how it might hook up to the datasette way of working - https://github.com/simonw/datasette . Eg:

  1. datasette has a simple launch path to run an interactive sql query form on Heroku or Zeit Now. Presumably chunks of that code could be reused to provide a simple launcher for scriptedforms on those sites?
  2. is there a way of bundling scriptedforms with datasette so that scriptedforms can easily call on api published as a datasette service?
SimonBiggs commented 6 years ago

I've never used datasette myself, but from a brief look a few ideas come to mind.

With regards to #2 one idea is you could make a neat set of python functions which use the requests module to call the datasette api. Then import those functions and use them as needed within your scripted form.

With respect to #1 I have had some difficulties hosting the jupyter server on services like heroku. I can't remember if I tried heroku specifically. But if the Jupyter notebook can't run on the service then ScriptedForms won't be able to either...

On Thu., 19 Apr. 2018, 11:20 pm Tony Hirst, notifications@github.com wrote:

Re: useful - yes... it will be very:-)

Im pondering also how it might hook up to the datasette way of working - https://github.com/simonw/datasette . Eg:

  1. datasette has a simple launch path to run an interactive sql query form on Heroku or Zeit Now. Presumably chunks of that code could be reused to provide a simple launcher for scriptedforms on those sites?
  2. is there a way of bundling scriptedforms with datasette so that scriptedforms can easily call on api published as a datasette service?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/SimonBiggs/scriptedforms/issues/244#issuecomment-382732069, or mute the thread https://github.com/notifications/unsubscribe-auth/AGQVezycXPxO4jxSUOH4UrLSBXQRZ1kJks5tqI8DgaJpZM4TbrHH .

psychemedia commented 6 years ago

By the by, quick post here: https://blog.ouseful.info/2018/04/19/creating-simple-interactive-forms-using-python-markdown-using-scriptedforms-jupyter/

psychemedia commented 6 years ago

Any ideas on the path I need to set to pick up the sqlite db file in the md file?

psychemedia commented 6 years ago

I've yet to try Jupyter on Heroku too, but a quick scout around suggests precedents. eg https://github.com/pl31/heroku-jupyter

SimonBiggs commented 6 years ago

The python should be running in that top directory. I don't see the database file in that directory?

If you run "from glob import glob" and then run "print(glob('*'))" you'll get a feel for what is available in your current working directory.

I'm not sure if this is the answer your after.

On Thu., 19 Apr. 2018, 11:41 pm Tony Hirst, notifications@github.com wrote:

I've yet to try Jupyter on Heroku too, but a quick scout around suggests precedents. eg https://github.com/pl31/heroku-jupyter

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/SimonBiggs/scriptedforms/issues/244#issuecomment-382739952, or mute the thread https://github.com/notifications/unsubscribe-auth/AGQVe9iKgvxNPdzWv_XNpUQwpE9y06-Eks5tqJP_gaJpZM4TbrHH .

SimonBiggs commented 6 years ago

I just had a play with https://mybinder.org/v2/gh/psychemedia/openlearn_scripted-form/master

Very cool :)

Also, thanks for the blog post :)

On Thu., 19 Apr. 2018, 11:45 pm Simon Biggs, mail@simonbiggs.net wrote:

The python should be running in that top directory. I don't see the database file in that directory?

If you run "from glob import glob" and then run "print(glob('*'))" you'll get a feel for what is available in your current working directory.

I'm not sure if this is the answer your after.

On Thu., 19 Apr. 2018, 11:41 pm Tony Hirst, notifications@github.com wrote:

I've yet to try Jupyter on Heroku too, but a quick scout around suggests precedents. eg https://github.com/pl31/heroku-jupyter

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/SimonBiggs/scriptedforms/issues/244#issuecomment-382739952, or mute the thread https://github.com/notifications/unsubscribe-auth/AGQVe9iKgvxNPdzWv_XNpUQwpE9y06-Eks5tqJP_gaJpZM4TbrHH .

psychemedia commented 6 years ago

On to do list is to embed the images. I guess Image() works in simple case? Here's one possible solution for embedding images in ttablw from dataframe: https://stackoverflow.com/questions/47038538/insert-matplotlib-images-into-a-pandas-dataframe (I don't think there's a way from panfas table styling: https://pandas.pydata.org/pandas-docs/stable/style.html ?)

SimonBiggs commented 6 years ago

I was actually thinking of implementing the following:

https://github.com/SimonBiggs/scriptedforms/issues/219

It might allow you to simply write

On Fri., 20 Apr. 2018, 7:58 am Tony Hirst, notifications@github.com wrote:

On to do list is to embed the images. I guess Image() works in simple case? Here's one possible solution for embedding images in ttablw from dataframe: https://stackoverflow.com/questions/47038538/insert-matplotlib-images-into-a-pandas-dataframe (I don't think there's a way from panfas table styling: https://pandas.pydata.org/pandas-docs/stable/style.html ?)

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/SimonBiggs/scriptedforms/issues/244#issuecomment-382893576, or mute the thread https://github.com/notifications/unsubscribe-auth/AGQVe1e784PvXkax8oXxxdmFkmTJX1grks5tqQiJgaJpZM4TbrHH .

SimonBiggs commented 6 years ago

In that set up it might also be possible to make that content container have a for loop so that it displays an image for every item in a list. A list which can be derived from your pandas table...

On Fri., 20 Apr. 2018, 8:17 am Simon Biggs, mail@simonbiggs.net wrote:

I was actually thinking of implementing the following:

https://github.com/SimonBiggs/scriptedforms/issues/219

It might allow you to simply write

On Fri., 20 Apr. 2018, 7:58 am Tony Hirst, notifications@github.com wrote:

On to do list is to embed the images. I guess Image() works in simple case? Here's one possible solution for embedding images in ttablw from dataframe: https://stackoverflow.com/questions/47038538/insert-matplotlib-images-into-a-pandas-dataframe (I don't think there's a way from panfas table styling: https://pandas.pydata.org/pandas-docs/stable/style.html ?)

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/SimonBiggs/scriptedforms/issues/244#issuecomment-382893576, or mute the thread https://github.com/notifications/unsubscribe-auth/AGQVe1e784PvXkax8oXxxdmFkmTJX1grks5tqQiJgaJpZM4TbrHH .

psychemedia commented 6 years ago

That would be handy, esp if I could create rows in a table with a desc cell and an image cell. This is now starting to get jinja like?

SimonBiggs commented 6 years ago

Well where possible I want to draw on standards that people are used to...

I'm actually primarily drawing on Angular syntax as that is what ScriptedForms is built on. I sort of trying to expose more and more of Angular + Jupyter combined in an easy to use way.

On Fri., 20 Apr. 2018, 6:02 pm Tony Hirst, notifications@github.com wrote:

That would be handy, esp if I could create rows in a table with a desc cell and an image cell. This is now starting to get jinja like?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/SimonBiggs/scriptedforms/issues/244#issuecomment-383016831, or mute the thread https://github.com/notifications/unsubscribe-auth/AGQVe2LrkUoywPT1cXTOnfS-YCsu_wtOks5tqZYZgaJpZM4TbrHH .

SimonBiggs commented 6 years ago

Actually a big thing I'm trying to expose are the following components:

https://material.angular.io/components/categories

On Fri., 20 Apr. 2018, 6:12 pm Simon Biggs, mail@simonbiggs.net wrote:

Well where possible I want to draw on standards that people are used to...

I'm actually primarily drawing on Angular syntax as that is what ScriptedForms is built on. I sort of trying to expose more and more of Angular + Jupyter combined in an easy to use way.

On Fri., 20 Apr. 2018, 6:02 pm Tony Hirst, notifications@github.com wrote:

That would be handy, esp if I could create rows in a table with a desc cell and an image cell. This is now starting to get jinja like?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/SimonBiggs/scriptedforms/issues/244#issuecomment-383016831, or mute the thread https://github.com/notifications/unsubscribe-auth/AGQVe2LrkUoywPT1cXTOnfS-YCsu_wtOks5tqZYZgaJpZM4TbrHH .

SimonBiggs commented 6 years ago

But do you know what. I think that's worth a shot. Instead of implementing this, what if I had a try at building in jinja2 templating. Making it so that jinja2 itself can be used if it is desired...

On Fri., 20 Apr. 2018, 6:16 pm Simon Biggs, mail@simonbiggs.net wrote:

Actually a big thing I'm trying to expose are the following components:

https://material.angular.io/components/categories

On Fri., 20 Apr. 2018, 6:12 pm Simon Biggs, mail@simonbiggs.net wrote:

Well where possible I want to draw on standards that people are used to...

I'm actually primarily drawing on Angular syntax as that is what ScriptedForms is built on. I sort of trying to expose more and more of Angular + Jupyter combined in an easy to use way.

On Fri., 20 Apr. 2018, 6:02 pm Tony Hirst, notifications@github.com wrote:

That would be handy, esp if I could create rows in a table with a desc cell and an image cell. This is now starting to get jinja like?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/SimonBiggs/scriptedforms/issues/244#issuecomment-383016831, or mute the thread https://github.com/notifications/unsubscribe-auth/AGQVe2LrkUoywPT1cXTOnfS-YCsu_wtOks5tqZYZgaJpZM4TbrHH .

SimonBiggs commented 6 years ago

It doesn't have to be used of course. But as people need it, they are free to use it.

On Fri., 20 Apr. 2018, 6:50 pm Simon Biggs, mail@simonbiggs.net wrote:

But do you know what. I think that's worth a shot. Instead of implementing this, what if I had a try at building in jinja2 templating. Making it so that jinja2 itself can be used if it is desired...

On Fri., 20 Apr. 2018, 6:16 pm Simon Biggs, mail@simonbiggs.net wrote:

Actually a big thing I'm trying to expose are the following components:

https://material.angular.io/components/categories

On Fri., 20 Apr. 2018, 6:12 pm Simon Biggs, mail@simonbiggs.net wrote:

Well where possible I want to draw on standards that people are used to...

I'm actually primarily drawing on Angular syntax as that is what ScriptedForms is built on. I sort of trying to expose more and more of Angular + Jupyter combined in an easy to use way.

On Fri., 20 Apr. 2018, 6:02 pm Tony Hirst, notifications@github.com wrote:

That would be handy, esp if I could create rows in a table with a desc cell and an image cell. This is now starting to get jinja like?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/SimonBiggs/scriptedforms/issues/244#issuecomment-383016831, or mute the thread https://github.com/notifications/unsubscribe-auth/AGQVe2LrkUoywPT1cXTOnfS-YCsu_wtOks5tqZYZgaJpZM4TbrHH .

psychemedia commented 6 years ago

Angular another thing new to me. Feel I'm getting stretched ever thinner! Apols if I've sent you down a jinja rabbithole (I'm not up to speed with that properly either..! Just trying to make connections between different things I see in the wilds I inhabit.)

SimonBiggs commented 6 years ago

All good. I'm still just trying to sort things out. Not coding anything until I'm comfortable with what I've come up with.

On Fri., 20 Apr. 2018, 11:32 pm Tony Hirst, notifications@github.com wrote:

Angular another thing new to me. Feel I'm getting stretched ever thinner! Apols if I've sent you down a jinja rabbithole (I'm not up to speed with that properly either..! Just trying to make connections between different things I see in the wilds I inhabit.)

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/SimonBiggs/scriptedforms/issues/244#issuecomment-383096881, or mute the thread https://github.com/notifications/unsubscribe-auth/AGQVe1DuAX3gj_l8aeI_ZRa9_IABAaW4ks5tqeNjgaJpZM4TbrHH .