Wie lese ich eine .csv -Datei in einer quarto -shinyliven Anwendung?Python

Python-Programme
Anonymous
 Wie lese ich eine .csv -Datei in einer quarto -shinyliven Anwendung?

Post by Anonymous »

Dieser Code unten funktioniert bei der Quarto-Vorschau < /code> im Terminal.

Code: Select all

```{shinylive-python}
#| 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. Ein Code wie dieser bricht beispielsweise, weil ich nicht sicher bin, wie ich das Lesen von .csv 
Datei:
Lesen lassen soll

Code: Select all

```{shinylive-python}
#| 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>
Haben Sie Ideen? [url=viewtopic.php?t=14917]Ich möchte[/url] im Grunde genommen in der Lage sein, eine Vorschau von Quarto zu quarto 
diese Datei und diese App in diesem Chunk in Quarto ausführen.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post