Ich habe eine Flask -App, die über WebSockets mit meiner Benutzeroberfläche kommuniziert. Am Ende einer meiner Funktionen muss ich ein Diagramm für Handlungsplot anzeigen. Alles funktioniert gut, bis mein Projekt lokal vom Terminal läuft. Wenn ich mein Python -Projekt in einem Container hochgeladen habe, öffnet der Plotly keine neue Registerkarte in meinem Browser und ich kann es nicht manuell öffnen, da Plotly immer in einem neuen Port geöffnet wird. Meine Frage ist .. Wie kann ich Plotly eine neue Registerkarte öffnen lassen, während ich in einem Docker ausgeführt wird.
# Use an official Python runtime as a parent image
FROM python:3.11.1
# Set the working directory inside the container
WORKDIR /app
# Copy only the Backend folder into the container
COPY Backend /app
# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Expose the port Flask runs on
EXPOSE 8001 8050 62079
# Run Flask app
CMD ["python", "app.py"]
< /code>
"""Flask Application"""
from flask import Flask
from flask_socketio import SocketIO, emit
from services.network_monitoring import (disable_port)
app = Flask(__name__)
# Enable usage of websockets
socketio = SocketIO(cors_allowed_origins="*", async_mode="threading")
socketio.init_app(app)
# ---- Helper Functions ----- #
def is_any_none(*args):
"""Checks if any of the element is none"""
return any(arg is None or arg == "" for arg in args)
# ----- Endpoints ----- #
@socketio.on("/enablePort")
def enable_snmp_port(data):
"""Enable port"""
ip_target = data["data"].get("ipTarget", None)
community = data["data"].get("community", None)
port_to_enable = data["data"].get("portToEnable", None)
if is_any_none(ip_target, community, port_to_enable):
emit("error", {"smallTerminalError": "Invalid IP, community or portToEnable"})
else:
enable_port(socketio, ip_target, community, port_to_enable)
# ----- Socket Consumer ----- #
@socketio.on('connect')
def handle_connect():
"""Handles connecting to WebSocket"""
print("WebSocket client connected")
emit('connection', {"connection": "Connected to WebSocket!"})
@socketio.on('disconnect')
def handle_disconnect():
"""Handles disconnecting to WebSocket"""
print("Disconnection WebSocket client")
emit('connection', {"connection": "Disconnected from WebSocket!"})
if __name__ == '__main__':
socketio.run(app, host="0.0.0.0", debug=True, port=8001)
< /code>
und wenn es hier wichtig ist, ist meine Handlung: < /p>
def plot_graph():
print("PLOTLY ENTERED")
# Create a subplot with 4 rows and 1 column
fig = make_subplots(
rows=4, cols=1,
shared_xaxes=True,
vertical_spacing=0.1,
subplot_titles=[
'In Errors',
'Out Errors',
'In Traffic (Mbps)',
'Out Traffic (Mbps)'
]
)
# In Errors Bar Plot
fig.add_trace(
go.Bar(
x=portsw,
y=in_errors,
name='InError',
marker=dict(color='blue'),
text=[str(f(val)) for val in in_errors],
textposition='outside'
),
row=1, col=1
)
# Out Errors Bar Plot
fig.add_trace(
go.Bar(
x=portsw,
y=out_errors,
name='OutError',
marker=dict(color='skyblue'),
text=[str(f(val)) for val in out_errors],
textposition='outside'
),
row=2, col=1
)
# In Mbps Bar Plot
fig.add_trace(
go.Bar(
x=portsw,
y=in_mbits,
name='InMbps',
marker=dict(color='green'),
text=[str(f(val)) for val in in_mbits],
textposition='outside'
),
row=3, col=1
)
# Out Mbps Bar Plot
fig.add_trace(
go.Bar(
x=portsw,
y=out_mbits,
name='OutMbps',
marker=dict(color='orange'),
text=[str(f(val)) for val in out_mbits],
textposition='outside'
),
row=4, col=1
)
# Update layout for the entire figure
fig.update_layout(
title=f'{ip_target} - ({a[1]})',
height=1000,
showlegend=True,
title_x=0.5,
xaxis_title='Ports',
yaxis_title='Values',
)
# Update y-axes for each subplot
fig.update_yaxes(title_text="vh", row=1, col=1)
fig.update_yaxes(title_text="izh", row=2, col=1)
fig.update_yaxes(title_text="vht", row=3, col=1)
fig.update_yaxes(title_text="izht", row=4, col=1)
# Show the figure
fig.show()
Ich habe eine Flask -App, die über WebSockets mit meiner Benutzeroberfläche kommuniziert. Am Ende einer meiner Funktionen muss ich ein Diagramm für Handlungsplot anzeigen. Alles funktioniert gut, bis mein Projekt lokal vom Terminal läuft. Wenn ich mein Python -Projekt in einem Container hochgeladen habe, öffnet der Plotly keine neue Registerkarte in meinem Browser und ich kann es nicht manuell öffnen, da Plotly immer in einem neuen Port geöffnet wird. Meine Frage ist .. Wie kann ich Plotly eine neue Registerkarte öffnen lassen, während ich in einem Docker ausgeführt wird.[code]# Use an official Python runtime as a parent image FROM python:3.11.1
# Set the working directory inside the container WORKDIR /app
# Copy only the Backend folder into the container COPY Backend /app
# Install dependencies RUN pip install --no-cache-dir -r requirements.txt
# Expose the port Flask runs on EXPOSE 8001 8050 62079
if is_any_none(ip_target, community, port_to_enable): emit("error", {"smallTerminalError": "Invalid IP, community or portToEnable"}) else: enable_port(socketio, ip_target, community, port_to_enable) # ----- Socket Consumer ----- # @socketio.on('connect') def handle_connect(): """Handles connecting to WebSocket"""
print("WebSocket client connected") emit('connection', {"connection": "Connected to WebSocket!"})
@socketio.on('disconnect') def handle_disconnect(): """Handles disconnecting to WebSocket"""
print("Disconnection WebSocket client") emit('connection', {"connection": "Disconnected from WebSocket!"})
if __name__ == '__main__': socketio.run(app, host="0.0.0.0", debug=True, port=8001)
< /code> und wenn es hier wichtig ist, ist meine Handlung: < /p> def plot_graph(): print("PLOTLY ENTERED")
# Create a subplot with 4 rows and 1 column fig = make_subplots( rows=4, cols=1, shared_xaxes=True, vertical_spacing=0.1, subplot_titles=[ 'In Errors', 'Out Errors', 'In Traffic (Mbps)', 'Out Traffic (Mbps)' ] )
# In Errors Bar Plot fig.add_trace( go.Bar( x=portsw, y=in_errors, name='InError', marker=dict(color='blue'), text=[str(f(val)) for val in in_errors], textposition='outside' ), row=1, col=1 )
# Out Errors Bar Plot fig.add_trace( go.Bar( x=portsw, y=out_errors, name='OutError', marker=dict(color='skyblue'), text=[str(f(val)) for val in out_errors], textposition='outside' ), row=2, col=1 )
# In Mbps Bar Plot fig.add_trace( go.Bar( x=portsw, y=in_mbits, name='InMbps', marker=dict(color='green'), text=[str(f(val)) for val in in_mbits], textposition='outside' ), row=3, col=1 )
# Out Mbps Bar Plot fig.add_trace( go.Bar( x=portsw, y=out_mbits, name='OutMbps', marker=dict(color='orange'), text=[str(f(val)) for val in out_mbits], textposition='outside' ), row=4, col=1 )
# Update layout for the entire figure fig.update_layout( title=f'{ip_target} - ({a[1]})', height=1000, showlegend=True, title_x=0.5, xaxis_title='Ports', yaxis_title='Values', )
# Update y-axes for each subplot fig.update_yaxes(title_text="vh", row=1, col=1) fig.update_yaxes(title_text="izh", row=2, col=1) fig.update_yaxes(title_text="vht", row=3, col=1) fig.update_yaxes(title_text="izht", row=4, col=1)
Ich möchte Open-Webui als Python-App ausführen, wie sie mit Python xxx.py zu beginnen, aber ich sehe nicht wie. Es scheint alles in Python zu sein, aber es gibt einen mysteriösen (für mich)...
Dies ist bei einem 400-MB-Archiv innerhalb von Sekunden abgeschlossen.
private static async Task ExtractFilesAsync(this ZipArchive archive, string destination, IProgress progress = null)
{
await...
Ich versuche, in OPEN AI einen Agenten zu erstellen, der sich basierend auf Benutzereingaben beim VS-Codeserver authentifiziert. Der VS-Codeserver wird im Docker-Container docker-vscode-1 ausgeführt....
Ich leite Docker 27.4.0 unter Windows aus. Die Windows -Version ist 11 (24H2 OS Build 26100.3476). Die fraglichen Lösungen 24319662 scheinen für mich nicht zu funktionieren (vielleicht). Was die...
Ich versuche, ein einfaches Candlestick-Diagramm aus OHLCV-Daten zu zeichnen, die von yfinance abgerufen wurden.
Das ist mein Code:
import yfinance as yf
import pandas as pd
import...