queryverse / ElectronDisplay.jl

An Electron.jl based figure and table display.
Other
85 stars 17 forks source link

Support html and markdown MIMEs #8

Closed tkf closed 5 years ago

tkf commented 5 years ago

This PR first adds support for HTML and markdown. I then noticed that popping up ElectronDisplay window every time I do ?thing could be annoying so I added CONFIG.showable option to let users fully control the behavior. It also adds and exports a function electrondisplay([mime,] x) to forcefully display x in ElectronDisplay.

CSS for markdown output is taken from https://github.com/sindresorhus/github-markdown-css. I just found it with a quick googling but the output looks good to me.

davidanthoff commented 5 years ago

Awesome!

But maybe we could make the default to not capture html and markdown, i.e. to get that behavior users would by default either have to change the config or use electrondisplay? I'm in particular worried about DataFrame, I think a lot of folks would probably by default prefer the REPL output to the HTML output in a separate window.

Two random other thoughts: it would be really nice if there was a julia config story for things like that, so that packages don't have to come up with something... A shortcut would be a PackageConfig package that one could for example load in startup.jl, so config options for various packages in the startup script (without loading all those packages), and then a package like this one here could access such config values... Certainly something post-this PR, and I think the way the config is handled is great for now, just a general idea I've had a couple of times now.

Other random thought: At some point it would be neat to add support for the application/vnd.dataresource+json MIME type with a nice table grid story. Everything in queryverse already supports that MIME type (right now the only client that picks that up is nteract).

Sorry for the babble here, I think if we could just change the default config story I mentioned in the second paragraph, we can merge this right away.

tkf commented 5 years ago

I changed the default CONFIG.showable to

electron_showable(m, x) = m ∉ ("text/html", "text/markdown") && showable(m, x)

really nice if there was a julia config story for things like that, so that packages don't have to come up with something

Yeah, I totally agree. I'm wondering if it's sufficient to have a very "lightweight convention" (i.e., no additional package). For example, use Main.__config__.<package name>.<option> for each package so that users can write

module __config__

module ElectronDisplay
    single_window = true
    showable = Base.showable
end

end

in startup.jl. Of course, each package can use arbitrary nested namespace.

A downside of using module is that mutating configuration on-the-fly is hard. But then the upside is that you can use Revise.includet so that editing file would automatically refresh the configuration. That is to say, you can do

using Revise
includet("config.jl")

in startup.jl and then put module __config__ ... end in ~/.julia/config/config.jl.

At some point it would be neat to add support for the application/vnd.dataresource+json MIME type

Sounds like a great idea. Is it as easy as, e.g., Vega Lite support? That is to say, is there any easy-to-use Javascript library we can bundle in ElectronDisplay.jl?

davidanthoff commented 5 years ago

I merged and tagged a release, so should be out soon! Thanks again :)

I like the idea of a convention instead of a package. I guess another option would be to just use maybe nested Dicts, that would get around the modification problem? But I also think this would actually be a good thing for the stdlib, so that it is always available, and then it could provide a nice API...

At some point it would be neat to add support for the application/vnd.dataresource+json MIME type

Sounds like a great idea. Is it as easy as, e.g., Vega Lite support? That is to say, is there any easy-to-use Javascript library we can bundle in ElectronDisplay.jl?

Probably ;) There seem to be a thousand different javascript grid options around, and I always was overwhelmed by the choice. The one that looks most awesome is what they used in https://marketplace.visualstudio.com/items?itemName=GrapeCity.gc-excelviewer, but I think that is not open source, unfortunately... https://github.com/JuliaComputing/TableView.jl uses something, so that might also be a good starting point. My guess is that the whole thing is very straightforward if one can identify the grid control.

tkf commented 5 years ago

Thanks for review & merge & release!

I guess another option would be to just use maybe nested Dicts, that would get around the modification problem?

Yeah, it does. I just thought module approach was cute that I don't need to write extra brackets.

My guess is that the whole thing is very straightforward if one can identify the grid control.

Finding a good Javascript library sounds very challenging :) but ag-grid used in https://github.com/JuliaComputing/TableView.jl/pull/6 seems to be a super rich library.