Is it possible to include the add_filter() function within a shortcode function

It should be possible but you will have to be aware of timing issues. Your shortcode will have to execute before whatever hook you are hooking into.

That is, you can’t hook into wp_enqueue_scripts or wp_head but you should be able to hook into later hooks like wp_footer. I suspect that timing is the problem.