Just like Bart in the post before I still get an empty graph when trying to plot anything other then a simple list like in the example from the tutorial. Iāve tried to plot a single column dict as well as a pandas serie.
This is a piece of the code. However, Iām not sure if I have anything in the dict as I can not really verifiy that anywhere. When I click the download button, it should update the HiddenField and give an output to the plotly graph.
I see that you are combining a DownloadResult and a SetParamsResult, this is not possible, only single results are supported (see the ViktorResultdocumentation):
Currently, the serialisation only accounts for the following (backward compatible) combinations:
a single optimization result
a single set_params result
a single download result
So the values are not set on the HiddenField, which cause the graph to be empty.
Furthermore, it is not required to convert a File to a StringIO as read_csv can also use a buffer as input, e.g.:
path_file_4 = File.from_path(Path(__file__).parent / "df_failures.csv")
with path_file_4.open() as f:
df_failures = pd.read_csv(f, sep=";")
Assuming the methods in your post are on the same controller you can add the parsing of the csv to the get_plotly_view method and select a column of the dataframe for the x and y values of the bar chart (e.g. y=df["TBT"]). You can find examples from the plotly documentation here: https://plotly.com/python/bar-charts/#basic-bar-charts-with-plotlygraphobjects. If you only specify a y-value the x-values will be the indices of the corresponding y-values.
Thank you very much for the tips! I didnāt know that the print statement works. Thatās a great tip!
Also the charts works when I parse the CSV directly in the Plotly controller. However I need a way to read and write tables and use them in different decorators. I was hoping the HiddenField could store my different dicts, but I understand now that I can not store an entire dict in a HiddenField. Could I use a writable file object for that?
It is possible to store an dictionary on a HiddenField, it is just not possible to combine this action together with a DownloadResult / DownloadButton. If you want to update your parametrization from the user interface you should use a SetParamsButton, see the documentation here: User input, fields and buttons - Set params using a button | VIKTOR Documentation.
If parsing of the csvās is cheap (time-wise) it is not really a problem to repeat the parsing on each controller method to reduce complexity. If the user uploads the csvās you can also choose to parse and store the result with a ParamsFromFile decorator (Managing files - Uploading files | VIKTOR Documentation).
I think you set the wrong params in download_spreadsheet, as you explicitly set the name argument on HiddenField (thus overwriting the default location in params). Replacing the SetParamsResult with the following should solve your problem:
Based on your other post, the method download_spreadsheet returns a SetParamsResult, but I suspect is called by a DownloadButton. You would need a SetParamsButton instead.