1111import maidr
1212from shiny import App , reactive , render , ui
1313from shiny .types import FileInfo
14+ import datetime
15+ import re
1416
1517# Import plot modules
1618from plots .utils import color_palettes
@@ -516,12 +518,12 @@ def utf8_open(*args, **kwargs):
516518 ui .div (
517519 ui .input_action_button (
518520 "download_graphics_custom" ,
519- "Download Graphics " ,
521+ "Download Graph in *.svg " ,
520522 class_ = "btn btn-primary" ,
521523 ),
522524 ui .input_action_button (
523525 "download_html_custom" ,
524- "Download Multimodal Plot" ,
526+ "Download Multimodal Plot in *.html " ,
525527 class_ = "btn btn-secondary" ,
526528 ),
527529 ui .input_action_button (
@@ -565,12 +567,12 @@ def utf8_open(*args, **kwargs):
565567 ui .div (
566568 ui .input_action_button (
567569 "download_graphics_histogram" ,
568- "Download Graphics " ,
570+ "Download Graph in *.svg " ,
569571 class_ = "btn btn-primary" ,
570572 ),
571573 ui .input_action_button (
572574 "download_html_histogram" ,
573- "Download Multimodal Plot" ,
575+ "Download Multimodal Plot in *.html " ,
574576 class_ = "btn btn-secondary" ,
575577 ),
576578 ui .input_action_button (
@@ -607,12 +609,12 @@ def utf8_open(*args, **kwargs):
607609 ui .div (
608610 ui .input_action_button (
609611 "download_graphics_boxplot" ,
610- "Download Graphics " ,
612+ "Download Graph in *.svg " ,
611613 class_ = "btn btn-primary" ,
612614 ),
613615 ui .input_action_button (
614616 "download_html_boxplot" ,
615- "Download Multimodal Plot" ,
617+ "Download Multimodal Plot in *.html " ,
616618 class_ = "btn btn-secondary" ,
617619 ),
618620 ui .input_action_button (
@@ -650,12 +652,12 @@ def utf8_open(*args, **kwargs):
650652 ui .div (
651653 ui .input_action_button (
652654 "download_graphics_scatter" ,
653- "Download Graphics " ,
655+ "Download Graph in *.svg " ,
654656 class_ = "btn btn-primary" ,
655657 ),
656658 ui .input_action_button (
657659 "download_html_scatter" ,
658- "Download Multimodal Plot" ,
660+ "Download Multimodal Plot in *.html " ,
659661 class_ = "btn btn-secondary" ,
660662 ),
661663 ui .input_action_button (
@@ -681,12 +683,12 @@ def utf8_open(*args, **kwargs):
681683 ui .div (
682684 ui .input_action_button (
683685 "download_graphics_barplot" ,
684- "Download Graphics " ,
686+ "Download Graph in *.svg " ,
685687 class_ = "btn btn-primary" ,
686688 ),
687689 ui .input_action_button (
688690 "download_html_barplot" ,
689- "Download Multimodal Plot" ,
691+ "Download Multimodal Plot in *.html " ,
690692 class_ = "btn btn-secondary" ,
691693 ),
692694 ui .input_action_button (
@@ -723,12 +725,12 @@ def utf8_open(*args, **kwargs):
723725 ui .div (
724726 ui .input_action_button (
725727 "download_graphics_lineplot" ,
726- "Download Graphics " ,
728+ "Download Graph in *.svg " ,
727729 class_ = "btn btn-primary" ,
728730 ),
729731 ui .input_action_button (
730732 "download_html_lineplot" ,
731- "Download Multimodal Plot" ,
733+ "Download Multimodal Plot in *.html " ,
732734 class_ = "btn btn-secondary" ,
733735 ),
734736 ui .input_action_button (
@@ -758,12 +760,12 @@ def utf8_open(*args, **kwargs):
758760 ui .div (
759761 ui .input_action_button (
760762 "download_graphics_heatmap" ,
761- "Download Graphics " ,
763+ "Download Graph in *.svg " ,
762764 class_ = "btn btn-primary" ,
763765 ),
764766 ui .input_action_button (
765767 "download_html_heatmap" ,
766- "Download Multimodal Plot" ,
768+ "Download Multimodal Plot in *.html " ,
767769 class_ = "btn btn-secondary" ,
768770 ),
769771 ui .input_action_button (
@@ -800,12 +802,12 @@ def utf8_open(*args, **kwargs):
800802 ui .div (
801803 ui .input_action_button (
802804 "download_graphics_multiline" ,
803- "Download Graphics " ,
805+ "Download Graph in *.svg " ,
804806 class_ = "btn btn-primary" ,
805807 ),
806808 ui .input_action_button (
807809 "download_html_multiline" ,
808- "Download Multimodal Plot" ,
810+ "Download Multimodal Plot in *.html " ,
809811 class_ = "btn btn-secondary" ,
810812 ),
811813 ui .input_action_button (
@@ -847,12 +849,12 @@ def utf8_open(*args, **kwargs):
847849 ui .div (
848850 ui .input_action_button (
849851 "download_graphics_multilayer" ,
850- "Download Graphics " ,
852+ "Download Graph in *.svg " ,
851853 class_ = "btn btn-primary" ,
852854 ),
853855 ui .input_action_button (
854856 "download_html_multilayer" ,
855- "Download Multimodal Plot" ,
857+ "Download Multimodal Plot in *.html " ,
856858 class_ = "btn btn-secondary" ,
857859 ),
858860 ui .input_action_button (
@@ -874,12 +876,12 @@ def utf8_open(*args, **kwargs):
874876 ui .div (
875877 ui .input_action_button (
876878 "download_graphics_multipanel" ,
877- "Download Graphics " ,
879+ "Download Graph in *.svg " ,
878880 class_ = "btn btn-primary" ,
879881 ),
880882 ui .input_action_button (
881883 "download_html_multipanel" ,
882- "Download Multimodal Plot" ,
884+ "Download Multimodal Plot in *.html " ,
883885 class_ = "btn btn-secondary" ,
884886 ),
885887 ui .input_action_button (
@@ -923,12 +925,12 @@ def utf8_open(*args, **kwargs):
923925 ui .div (
924926 ui .input_action_button (
925927 "download_graphics_candlestick" ,
926- "Download Graphics " ,
928+ "Download Graph in *.svg " ,
927929 class_ = "btn btn-primary" ,
928930 ),
929931 ui .input_action_button (
930932 "download_html_candlestick" ,
931- "Download Multimodal Plot" ,
933+ "Download Multimodal Plot in *.html " ,
932934 class_ = "btn btn-secondary" ,
933935 ),
934936 ui .input_action_button (
@@ -1173,8 +1175,17 @@ async def trigger_html_download(plot_type_suffix):
11731175 with open (temp_filepath , 'r' , encoding = 'utf-8' ) as f :
11741176 html_content = f .read ()
11751177
1176- # Generate filename
1177- filename = f"accessible_plot_{ plot_type_suffix } _{ uuid .uuid4 ().hex [:8 ]} .html"
1178+ # Generate filename using new scheme: titleofplot_plottype_timestamp
1179+ plot_title = "plot"
1180+ try :
1181+ if fig and fig .get_axes ():
1182+ title_text = fig .get_axes ()[0 ].get_title ()
1183+ if title_text :
1184+ plot_title = re .sub (r"\W+" , "_" , title_text .strip ()).strip ("_" )
1185+ except Exception :
1186+ pass
1187+ timestamp = datetime .datetime .now ().strftime ("%Y%m%d_%H%M%S" )
1188+ filename = f"{ plot_title } _{ plot_type_suffix } _{ timestamp } .html"
11781189
11791190 # Send to JavaScript for download
11801191 await session .send_custom_message ("download_file" , {
@@ -1199,7 +1210,13 @@ async def trigger_html_download(plot_type_suffix):
11991210 @reactive .effect
12001211 @reactive .event (input .download_html_custom )
12011212 async def download_html_custom_clicked ():
1202- await trigger_html_download ("custom" )
1213+ # Include the selected plot type in the suffix for custom downloads
1214+ plot_type = getattr (input , 'plot_type' , lambda : None )()
1215+ if plot_type :
1216+ suffix = "custom_" + re .sub (r"\W+" , "_" , plot_type .strip ().lower ())
1217+ else :
1218+ suffix = "custom"
1219+ await trigger_html_download (suffix )
12031220
12041221 @reactive .effect
12051222 @reactive .event (input .download_html_histogram )
@@ -1664,7 +1681,17 @@ async def trigger_svg_download(plot_type_suffix):
16641681 svg_content = buffer .getvalue ()
16651682 buffer .close ()
16661683
1667- filename = f"accessible_plot_{ plot_type_suffix } _{ uuid .uuid4 ().hex [:8 ]} .svg"
1684+ # Generate filename using new scheme: titleofplot_plottype_timestamp
1685+ plot_title = "plot"
1686+ try :
1687+ if fig and fig .get_axes ():
1688+ title_text = fig .get_axes ()[0 ].get_title ()
1689+ if title_text :
1690+ plot_title = re .sub (r"\W+" , "_" , title_text .strip ()).strip ("_" )
1691+ except Exception :
1692+ pass
1693+ timestamp = datetime .datetime .now ().strftime ("%Y%m%d_%H%M%S" )
1694+ filename = f"{ plot_title } _{ plot_type_suffix } _{ timestamp } .svg"
16681695
16691696 # Send to browser
16701697 await session .send_custom_message ("download_file" , {
@@ -1683,7 +1710,12 @@ async def trigger_svg_download(plot_type_suffix):
16831710 @reactive .effect
16841711 @reactive .event (input .download_graphics_custom )
16851712 async def download_graphics_custom_clicked ():
1686- await trigger_svg_download ("custom" )
1713+ plot_type = getattr (input , 'plot_type' , lambda : None )()
1714+ if plot_type :
1715+ suffix = "custom_" + re .sub (r"\W+" , "_" , plot_type .strip ().lower ())
1716+ else :
1717+ suffix = "custom"
1718+ await trigger_svg_download (suffix )
16871719
16881720 @reactive .effect
16891721 @reactive .event (input .download_graphics_histogram )
0 commit comments