aar2dee2
Download processed data from Kino.listen
Hey, Livebook devs!
I’m listening to form submissions in a Livebook with:
Kino.listen(crawler_form,
fn event ->
json_output =
Crawler.test_output(event.data)
|> Jason.encode!()
IO.inspect(json_output)
end)
I want to write json_output to a file and make the file available for download, like in Kino.Download.new. How do I pass data from Kino.listen to Kino.Download.new?
Kino.listen(crawler_form,
fn event ->
# Create a function that generates the JSON output
content_fun = fn ->
Crawler.test_output(event.data)
|> Jason.encode!()
end
# Create the download button
Kino.Download.new(content_fun, filename: "output.json")
end)
Marked As Solved
jonatanklosko
Creator of Livebook
Hey @aar2dee2! Here’s an example:
# Form -> download
```elixir
Mix.install([
{:kino, "~> 0.10.0"}
])
```
## Section
```elixir
form =
Kino.Control.form(
[text: Kino.Input.textarea("Content")],
submit: "Submit"
)
```
```elixir
frame = Kino.Frame.new()
```
```elixir
Kino.listen(form, fn event ->
content_fun = fn ->
event.data.text
end
Kino.Frame.render(frame, Kino.Download.new(content_fun), to: event.origin)
end)
```
Note that to: event.origin makes the download button only available to the user who submitted the form, you can omit it, if the button should be available to everyone.
4
Also Liked
aar2dee2
Popular in Questions
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
I have a super simple question about elixir - how would I take a file like this
foo
bar
baz
and output a new file that enumerates th...
New
I would like to know what is the best IDE for elixir development?
New
lets say i have a sample like
a = 20; b = 10;
if (a > b) do
{:ok, "a"}
end
if (a < b) do
{:ok, b}
end
if (a == b) do
{:ok, "equa...
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Hi! May someone helps me, please!
I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
Other popular topics
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
New
Hi everyone,
I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
Hello everyone,
I try to use an Javascript Event Handler in my root.html.leex file.
Therefore I created a function in the app.js file: ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









