How to programmatically add a facet to Facet API based on returned facet values? I would like to programmatically and conditionally show a facet block, if the returned values match some certain criteria. I have not found any solutions so far.
For example, if a facet returns 25 apples, I would like to show an additional facet that does some calculation on this value.
If you used Search API, this code should help you:

$delta = facetapi_hash_delta(facetapi_build_delta('search_api@INDEX_MACHINE_NAME', 'block', FACET_NAME));
print render(module_invoke('facetapi', 'block_view', $delta));