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)