Python Shiny Live in QuartoPython

Python-Programme
Anonymous
 Python Shiny Live in Quarto

Post by Anonymous »

Dieser Code unten funktioniert bei der Quarto-Vorschau < /code> im Terminal.#| standalone: true
#| layout: vertical
#| viewerHeight: 250

from shiny import *

app_ui = ui.page_fluid(
ui.input_slider("n", "N", 0, 100, 40),
ui.output_text_verbatim("txt"),
ui.output_text_verbatim("txt2")
)

def server(input, output, session):
@output
@render.text
def txt():
return f"The value of n*2 is {input.n() * 2}"

@render.text
def txt2():
return f"The value of n**2 is {input.n() ** 2}"

app = App(app_ui, server)

< /code>
Aber ich weiß nicht, wie man einen Datenrahmen liest und einen Handlungsprotokoll ausführt. Zum Beispiel bricht ein Code ein, weil ich nicht sicher bin, wie ich diese CSV -Datei lesen kann: < /p>
#| standalone: true
#| viewerHeight: 420
#| viewerWidth: 500

from shiny import App, ui, render
import pandas as pd
import plotly.express as px
from pathlib import Path

app_ui = ui.page_fluid(
ui.layout_sidebar(
ui.sidebar(
ui.input_slider("cylinder", "Cylinder", 4, 6, 8, step=1)
),
ui.output_plot("plot"),
),
)

@reactive.calc
def dat():
infile = Path(__file__).parent / "exampledf.csv"
return pd.read_csv(infile)

def server(input):
@render.plot(alt="ScatterPlot function")
def plot():
file_path= Path(__file__).parent /'exampledf.csv'

# Load the dataset globally so it can be reused
df = dat()#pd.read_csv(file_path)

# Subset the DataFrame using the slider value
minidf = df[df.cylinders == input.cylinder()].copy()

# Create a plotly express scatter figure
fig = px.scatter(
minidf,
x="horsepower",
y="weight",
title="Scatter Plot of Horsepower vs Weight"
)
return fig

app = App(app_ui, server)

< /code>
Ideen? Im Grunde möchte ich in der Lage sein, diese Datei vorschau zu machen und diese App in diesem Stück in Quarto auszuführen.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post