get_template_part
is echoing the HTML code. and the shortcode function must return the content.
then you can try that :
function custom_code($attr, $content, $tag)
{
ob_start();
get_template_part( 'page', 'example' );
$content = ob_get_clean();
return $content;
}
add_shortcode( 'custom', 'custom_code' );