Skip to content

feat: Publish scripts as Quarto documents #3323

@brooklynbagel

Description

@brooklynbagel

Description

Connect supports rendering scripts (.py and .R) files as Quarto documents, see https://docs.posit.co/connect/user/scripts/. There's some front-matter that needs to be added that makes Quarto recognize them as renderable, see https://quarto.org/docs/computations/render-scripts.html#syntax and the scripts are renders using Jupyter or Knitr. However, the Publisher extension does not know how to handle these types of files. For example, if I try to publish the following R script

#' ---
#' title: "R script file"
#' ---

# Randomly generate data that acts as 30-day trailing unit sales.
today <- Sys.Date()
data <- data.frame(
  Date = today - 1:30,
  Sales = sample(75:100, 30, replace = TRUE)
)

# Write a CSV for downstream use.
write.csv(data, "sales.csv", row.names = FALSE)

#' Download [CSV](sales.csv)

Publisher generates the following configuration

# Configuration file generated by Posit Publisher.
# Please review and modify as needed. See the documentation for more options:
# https://github.com/posit-dev/publisher/blob/main/docs/configuration.md
product_type = 'connect'
'$schema' = 'https://cdn.posit.co/publisher/schemas/posit-publishing-schema-v3.json'
type = 'unknown'
entrypoint = 'rscript.R'
validate = true
files = [
  '/rscript.R',
  '/renv.lock',
  '/.posit/publish/render-rscript-reprex-545N.toml',
  '/.posit/publish/deployments/deployment-OVT9.toml'
]
title = 'render-rscript-reprex'

Where the type config should be quarto-static, and an [r] and [quarto] block are missing.

Note

It does appear that Publisher knows how to handle .py handles rendered with Jupyter.

# %% [markdown]
# ---
# title: "Python script file"
# ---

# %%
import datetime
import pandas as pd
import random

# Randomly generate data that acts as 30-day trailing unit sales.
today = datetime.date.today()
data = pd.DataFrame({
    'Date': pd.date_range(
        today - datetime.timedelta(days=30),
        today - datetime.timedelta(days=1),
    ),
    'Sales': [random.randint(75, 100) for _ in range(1, 31)],
})


# Write a CSV for downstream use.
data.to_csv("sales.csv", index=False)

# %% [markdown]
# Download [CSV](sales.csv)

Publisher generates the configuration

# Configuration file generated by Posit Publisher.
# Please review and modify as needed. See the documentation for more options:
# https://github.com/posit-dev/publisher/blob/main/docs/configuration.md
product_type = 'connect'
'$schema' = 'https://cdn.posit.co/publisher/schemas/posit-publishing-schema-v3.json'
type = 'quarto-static'
entrypoint = 'pyscript.py'
validate = true
files = [
  '/pyscript.py',
  '/requirements.txt',
  '/renv.lock',
  '/.posit/publish/Python script file-HT68.toml',
  '/.posit/publish/deployments/deployment-GDCC.toml'
]
title = 'Python script file'

[python]

[quarto]
version = '1.7.32'
engines = ['jupyter']

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions