Revisiting "Getting the build an app example to work from the command-line"

I am revisiting Panel and feel it really is the most complete and poweful pure python offering available, having tried many. That being said I am more of an IDE guy than a Jupyter notebook guy. Each time I come back to Panel, I always forget how to serve my apps from PyCharm.

I remember panel serve so I searched for that but the cheatsheet that came up showed how to run it but it did not mention that you need to mark something as .servable.

I found my old thread on this topic but this time I am just trying to get the first part of the code to work, not the whole example.

I understood from the previous thread that you need to mark at least one Panel object with .servable() for panel serve to pick it up and render it in the served app. So I guess I need to create a panel object to wrap the holoviz scatter plot? Because the current code fails with the error: AttributeError: 'Scatter' object has no attribute 'servable'

import panel as pn
import hvplot.pandas
import pandas as pd
import numpy as np

pn.extension(design='material')

csv_file = ("https://raw.githubusercontent.com/holoviz/panel/main/examples/assets/occupancy.csv")
data = pd.read_csv(csv_file, parse_dates=["date"], index_col="date")

print(data.tail())

def transform_data(variable, window, sigma):
    ''' Calculates the rolling average and the outliers '''
    avg = data[variable].rolling(window=window).mean()
    residual = data[variable] - avg
    std = residual.rolling(window=window).std()
    outliers = np.abs(residual) > std * sigma
    return avg, avg[outliers]

def create_plot(variable="Temperature", window=30, sigma=10):
    ''' Plots the rolling average and the outliers '''
    avg, highlight = transform_data(variable, window, sigma)
    return avg.hvplot(height=300, width=400, legend=False) * highlight.hvplot.scatter(
        color="orange", padding=0.1, legend=False
    ).servable()

plot = create_plot(variable='Temperature', window=20, sigma=10)

print(plot)
plot

OK I figured it out:

import panel as pn
import hvplot.pandas
import pandas as pd
import numpy as np

pn.extension(design='material')

csv_file = ("https://raw.githubusercontent.com/holoviz/panel/main/examples/assets/occupancy.csv")
data = pd.read_csv(csv_file, parse_dates=["date"], index_col="date")

print(data.tail())

def transform_data(variable, window, sigma):
    ''' Calculates the rolling average and the outliers '''
    avg = data[variable].rolling(window=window).mean()
    residual = data[variable] - avg
    std = residual.rolling(window=window).std()
    outliers = np.abs(residual) > std * sigma
    return avg, avg[outliers]

def create_plot(variable="Temperature", window=30, sigma=10):
    ''' Plots the rolling average and the outliers '''
    avg, highlight = transform_data(variable, window, sigma)
    return avg.hvplot(height=300, width=400, legend=False) * highlight.hvplot.scatter(
        color="orange", padding=0.1, legend=False
    )

plot = create_plot(variable='Temperature', window=20, sigma=10)

first_app = pn.Column(plot)
first_app.servable()

Hi @metaperl,

I also make that mistake from time to time, i.e. trying to call .servable on an object returned by hvPlot or HoloViews. Maybe we can do something about it.