Dataspyre / Spyre:尝试让UI重定向回原来的httplink:

时间:2017-08-24 19:35:49

标签: python user-interface

我使用Dataspyre包在Python中运行此UI。

我想知道在输入参数并点击提交按钮后是否有办法将UI重定向回原始的httplink。

示例代码如下所示:

from spyre import server
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
import os

class test_ui(server.App):
    title = 'This is just a test UI'

    inputs = [
    {
    "type":"text",
    "key":"question1",
    "label":"Do you like Basketball?(Y/N)",
    "value":""
    },
    {
    "type":"text",
    "key":"question2",
    "label":"Do you like Baseball?(Y/N)",
    "value":""
    },
    {
    "type":"text",
    "key":"question3",
    "label":'Do you like Football?(Y/N)',
    "value":""
    }
    ]

    controls = [
    {
    "type":"button",
    "label":"submit",
    "id":"submit_action"
    }
    ]

    outputs = [
    {
    "type":'html',
    "control_id":"submit_action",
    "id":'display_parameters',
    "on_page_load" : True
    }
    ]

    def display_parameters(self, params):
        if params['question1'] =='' or params['question2'] == '' or  params['question3'] == '':
            return "Fields missing: Please submit all inputs in the UI"
        else:
            params_list = [params['question1'], params['question2'], params['question3']]
            count = 0
            for item in params_list:
                if item == 'Y':
                    count +=1

        if count > 0:
            data_dict = {"1":1,"2":2,"3":3}
            df = pd.DataFrame(data_dict.items(), columns=['Nothing1', 'Nothing2'])

            fig = plt.figure()
            fig.set_size_inches(15.5, 8.5)
            fig.suptitle('Nothing big deal')

            ax = fig.add_subplot(111)

            plt.plot(df['Nothing1'],df['Nothing2'], linewidth = 3.0)

            pp = PdfPages('Nothing.pdf')
            plt.savefig(pp, format='pdf')
            pp.close()

        else:
            pass

    app = test_ui()
    app.launch(port = 12345)

问题是,一旦输入参数(每个问题为Y)并提交,链接将更改为

http://127.0.0.1:12345/?question1=Y&question2=Y&question3=Y&

我想点击提交按钮后立即将其重定向回http://127.0.0.1:12345。有没有人有解决方案?

0 个答案:

没有答案