Skip to content

Commit

Permalink
small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
schlichtanders committed Jan 13, 2025
1 parent 8ad28e1 commit fa2bd58
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 90 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "JolinPluto"
uuid = "5b0b4ef8-f4e6-4363-b674-3f031f7b9530"
authors = ["Stephan Sahm <[email protected]> and contributors"]
version = "0.1.90"
version = "0.1.91"

[deps]
AbstractPlutoDingetjes = "6e696c72-6542-2067-7265-42206c756150"
Expand Down
70 changes: 0 additions & 70 deletions ext/PythonCallExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,75 +208,5 @@ function __init__()
end
end

# Here an alternative implementation which unfortunately does not really work because if the same is used multiple times, on the first load it will actually
# interfere with one another so that all widgets are duplicated 3 to 10 times, depending on how many widgets load the common dependency in parallel.
# function Base.show(io::IO, m::MIME"text/html", w::JolinPluto.IPyWidget)
# e = PythonCall.pyimport("ipywidgets.embed")
# data = e.embed_data(views=[w.widget], state=e.dependency_state([w.widget]))
# show(io, m, @htl """
# <div type="application/vnd.jupyter.widget-view+div">
# <script>
# if (window.ipywidgets_loaded == null){
# window.ipywidgets_loaded = true;
# (()=>{
# var s = document.createElement('script');
# s.src = "https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"
# // s.integrity = "sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA="
# s.type = "text/javascript"
# s.crossorigin = "anonymous"
# s.async = false // <- this is important
# currentScript.parentNode.insertBefore(s, currentScript.nextSibling)


# var s = document.createElement('script')
# s.src = "https://cdn.jsdelivr.net/npm/@jupyter-widgets/html-manager@*/dist/embed-amd.js"
# s["data-jupyter-widgets-cdn"] = "https://unpkg.com/"
# s["data-jupyter-widgets-cdn-only"] = ""
# s.crossorigin = "anonymous"
# s.async = false // <- this is important
# currentScript.parentNode.insertBefore(s, currentScript.nextSibling)
# })();
# }
# </script>
# <script>
# (()=>{
# "use strict";
# const div = currentScript.parentElement;
# // this is key so that the initial value won't be set to nothing immediately
# // this value property will be read out for the client-site initial value
# div.value = $(pyconvert(Any, w.widget.value))

# // TODO renderWidgets(div) has the advantage that no duplicates appear
# // however if the same ui is used multiple times on the website, they also won't be combined any longer into one synced state (which actually happens automatically without the div restriction)
# // still for now having no duplicates (why ever they appear without the div restriction) is better than no sync
# window.require(["@jupyter-widgets/html-manager/dist/libembed-amd"],
# (function(e) {
# // without this the second execution wouldn't show anything
# "complete" === document.readyState ? e.renderWidgets(div) : window.addEventListener("load", (function() {
# e.renderWidgets(div)
# }))
# })
# )
# })();
# </script>

# <!-- The state of all the widget models on the page -->
# <script type="application/vnd.jupyter.widget-state+json">
# $(pyconvert(Dict, data["manager_state"]))
# </script>
# <!-- This script tag will be replaced by the view's DOM tree -->
# <script type="application/vnd.jupyter.widget-view+json">
# $(pyconvert(Dict, data["view_specs"][0]))
# </script>

# <script>
# invalidation.then(() => {
# // cleanup here!
# })
# </script>
# </div>
# """)
# end


end
7 changes: 0 additions & 7 deletions ext/RCallExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,4 @@ function JolinPluto.lang_get_global(::Val{:r}, def::Symbol)
RCall.Const.GlobalEnv[def]
end

function __init__()
# this is crucial so that the path is set correctly
# while PythonCall does this by itself, RCall needs this manual help,
# which effects both plain Julia with RCall as well as PlutoR
CondaPkg.activate!(ENV)
end

end # module
23 changes: 11 additions & 12 deletions src/frontend.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
using EzXML
import AbstractPlutoDingetjes
import HypertextLiteral

# for HTML this is already defined inside PlutoRunner, but HypertextLiteral is not a dependency of PlutoRunner, hence we put it here
# this is needed for convenience so people don't have to wrap @htl into HTML for it to be interpolatable inside script tags
function Base.show(io::IO, ::MIME"text/javascript", htl::HypertextLiteral.Result)
html = sprint(show, MIME"text/html"(), htl)
# observablehq/stdlib.html is by default always available, hence this is always valid
# in case the user wants to use preact html, it just needs to be imported/shadowed respectively
write(io, "html`$html`")
end


"""
output_below()
Expand Down Expand Up @@ -141,18 +152,6 @@ function MD(args...; kwargs...)
end


# RCall's calling syntax does not support arbitrary types, but is good with functions
"""
_HTML("<h1> HTML String </h1>")
Just like HTML, but a function.
Background: RCall's calling syntax does not support arbitrary types, but is good with functions.
"""
function _HTML(args...; kwargs...)
HTML(args...; kwargs...)
end

"""
format_html(anything)
Expand Down

0 comments on commit fa2bd58

Please sign in to comment.