Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Specific starting apps for the editor only view #153

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
{
"engine": "r",
"examples": [
{
"category": "Editor",
"apps": ["editor"]
},
{
"category": "R examples",
"apps": [
Expand Down
1 change: 1 addition & 0 deletions examples/r/editor/about.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Editor
15 changes: 15 additions & 0 deletions examples/r/editor/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
library(shiny)
library(bslib)

ui <- page_fluid(
sliderInput("n", "N", 100, min = 0, max = 200),
verbatimTextOutput("result")
)

server <- function(input, output, session) {
output$result <- renderPrint({
cat("n * 2 =", input$n * 2)
})
}

shinyApp(ui, server)
16 changes: 10 additions & 6 deletions src/Components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -698,14 +698,18 @@ export function runApp(
if (pos) {
opts.selectedExample = exampleName;
} else {
// If we didn't find an example name from the URL hash, we'll just use
// the first available example.
pos = { categoryIndex: 0, index: 0 };
opts.selectedExample = sanitizeTitleForUrl(
exampleCategories[pos.categoryIndex].apps[pos.index].title,
// We didn't find an example name from the URL hash. If we have an
// example in the "Editor" category, use that, otherwise use the first
// available example in the list.
const editorCategory = (await getExampleCategories(appEngine)).filter(
(cat) => cat.category == "Editor",
);
const categories =
editorCategory.length > 0 ? editorCategory : exampleCategories;
const { title, files } = categories[0].apps[0];
opts.selectedExample = sanitizeTitleForUrl(title);
startFiles = files;
}
startFiles = exampleCategories[pos.categoryIndex].apps[pos.index].files;
}
// If we get here, we're either not looking for a URL hash that points to
// code, or we didn't find such a hash.
Expand Down
6 changes: 5 additions & 1 deletion src/Components/ExampleSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export function ExampleSelector({
React.useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
(async () => {
setExampleCategories(await getExampleCategories(appEngine));
const categories = (await getExampleCategories(appEngine)).filter(
// Exclude the "Editor" category from the general examples list
(cat) => cat.category !== "Editor",
);
setExampleCategories(categories);
})();
}, [appEngine]);

Expand Down