a python callback function to javascript

I have a problem converting a python function to javascript. This is a part of my code:

def update_plot(attr, old, new):

yr = slider.value
if radio_button_group.active == 0:
txt = “Total”
if radio_button_group_sec.active == 0:
geosource = geosource_total
color_mapper.high = 5
txt2 = “Compared with 1997 data”
color_bar.major_label_overrides= tick_labels_n
hover = HoverTool(tooltips = [ (‘Country/region’,’@country’),(‘Rate’, ‘@%d’ %yr)])
title.text = txt +’ Issued, {}’.format(yr)
subtitle.text = txt2
p.patches(‘xs’,‘ys’, source = geosource,fill_color = {‘field’ :’%d’ %yr, ‘transform’:color_mapper},line_color = ‘black’, line_width = 0.25, fill_alpha = 1)
p.tools = [hover]

Unfortunately, I don’t know how to convert it to callback = CustomJS(args=dict(source=source), code=code) format. Any help would be appreciated.

Hi @Cna please edit your post to use code formatting so that the code is intelligible (either with the </> icon on the editing toolbar, or triple backtick ``` fences around the code blocks)

Dear @Bryan ,
Since I am a new user, apparently I am not allowed to edit/delete my post. I am resending my code here. Also, I will send what I tried to solve the problem. Here is the live version of what I am working on: https://visa-issued.herokuapp.com/
My goal is to create a standalone HTML/Js version of this site.
The python function:

def update_plot(attr, old, new):
    yr = slider.value
    if radio_button_group.active == 0:
        txt = "Total Visas"
        if radio_button_group_sec.active == 0:
            geosource = geosource_total
            color_mapper.high = 5
            txt2 = "Compared with 1997 data"
            color_bar.major_label_overrides= tick_labels_n
            hover = HoverTool(tooltips = [ ('Country/region','@country'),('Rate', '@%d' %yr)])
        elif radio_button_group_sec.active == 1:
            geosource = geosource_total_c
            color_mapper.high = 20
            txt2 = "Compared with issued in the current year"
            color_bar.major_label_overrides= tick_labels_p
            hover = HoverTool(tooltips = [ ('Country/region','@country'),('%', '@%d' %yr)])
    elif radio_button_group.active == 1:
        txt = "Student Visas"
        if radio_button_group_sec.active == 0:
            geosource = geosource_student
            color_mapper.high = 5
            color_bar.major_label_overrides= tick_labels_n
            txt2 = "Compared with 1997 data"
            hover = HoverTool(tooltips = [ ('Country/region','@country'),('Rate', '@%d' %yr)])
        elif radio_button_group_sec.active == 1:
            geosource = geosource_student_c
            color_mapper.high = 20
            txt2 = "Compared with issued in the current year"
            color_bar.major_label_overrides= tick_labels_p
            hover = HoverTool(tooltips = [ ('Country/region','@country'),('%', '@%d' %yr)])
    elif radio_button_group.active == 2:
        txt = "All Other Visas"
        if radio_button_group_sec.active == 0:
            geosource = geosource_all_other
            color_mapper.high = 5
            txt2 = "Compared with 1997 data"
            color_bar.major_label_overrides= tick_labels_n
            hover = HoverTool(tooltips = [ ('Country/region','@country'),('Rate', '@%d' %yr)])
        elif radio_button_group_sec.active == 1:
            geosource = geosource_all_other_c
            color_mapper.high = 20
            txt2 = "Compared with issued in the current year"
            color_bar.major_label_overrides= tick_labels_p
            hover = HoverTool(tooltips = [ ('Country/region','@country'),('%', '@%d' %yr)])
    title.text = txt +' Issued, {}'.format(yr)
    subtitle.text = txt2
    p.patches('xs','ys', source = geosource,fill_color = {'field' :'%d' %yr, 'transform' : color_mapper},line_color = 'black', line_width = 0.25, fill_alpha = 1)
    p.tools = [hover]

What I tried but did not work:
Please note that geosource_total, geosource_total_c, geosource_student, geosource_student_c, geosource_all_other, geosource_all_other_c are 6 GeoJSONDataSource objects that gained from 6 json files.

update_plot = CustomJS(args=dict(geosource_total=geosource_total, geosource_total_c=geosource_total_c, geosource_student=geosource_student, geosource_student_c=geosource_student_c, geosource_all_other=geosource_all_other, geosource_all_other_c = geosource_all_other_c), code=code)
code="""
    var geosource;
    var yr = slider.value;
    var first_radio_value = radio_button_group.active;
    var second_radio_value = radio_button_group_sec.active;
    var txt = "";
    var txt2 = "";
    if (first_radio_value == 0){
        txt = "Total Visas"
        if (second_radio_value == 0){
            geosource = geosource_total
            color_mapper.high = 5
            txt2 = "Compared with 1997 data"
            color_bar.major_label_overrides= tick_labels_n
            hover = HoverTool(tooltips = [ ('Country/region','@country'),('Rate', '@%d' %yr)])}
        elif (second_radio_value == 1){
            geosource = geosource_total_c
            color_mapper.high = 20
            txt2 = "Compared with issued in the current year"
            color_bar.major_label_overrides= tick_labels_p
            hover = HoverTool(tooltips = [ ('Country/region','@country'),('%', '@%d' %yr)])}}
    elif (first_radio_value == 1){
        txt = "Student Visas"
        if (second_radio_value == 0){
            geosource = geosource_student
            color_mapper.high = 5
            color_bar.major_label_overrides= tick_labels_n
            txt2 = "Compared with 1997 data"
            hover = HoverTool(tooltips = [ ('Country/region','@country'),('Rate', '@%d' %yr)])}
        elif (second_radio_value == 1){
            geosource = geosource_student_c
            color_mapper.high = 20
            txt2 = "Compared with issued in the current year"
            color_bar.major_label_overrides= tick_labels_p
            hover = HoverTool(tooltips = [ ('Country/region','@country'),('%', '@%d' %yr)])}}
    elif (first_radio_value == 2){
        txt = "All Other Visas"
        if (second_radio_value == 0){
            geosource = geosource_all_other
            color_mapper.high = 5
            txt2 = "Compared with 1997 data"
            color_bar.major_label_overrides= tick_labels_n
            hover = HoverTool(tooltips = [ ('Country/region','@country'),('Rate', '@%d' %yr)])}
        elif (second_radio_value == 1){
            geosource = geosource_all_other_c
            color_mapper.high = 20
            txt2 = "Compared with issued in the current year"
            color_bar.major_label_overrides= tick_labels_p
            hover = HoverTool(tooltips = [ ('Country/region','@country'),('%', '@%d' %yr)])}}
    title.text = txt +' Issued, {}'.format(yr);
    subtitle.text = txt2;
    p.patches('xs','ys', source = geosource,fill_color = {'field' :'%d' %yr, 'transform' : color_mapper},line_color = 'black', line_width = 0.25, fill_alpha = 1);
    p.tools = [hover];
    geosource.change.emit();"""