diff --git a/examples/index.json b/examples/index.json index 26a81105..793890f3 100644 --- a/examples/index.json +++ b/examples/index.json @@ -58,6 +58,10 @@ { "engine": "r", "examples": [ + { + "category": "Editor", + "apps": ["editor"] + }, { "category": "R examples", "apps": [ diff --git a/examples/r/editor/about.txt b/examples/r/editor/about.txt new file mode 100644 index 00000000..65761ad1 --- /dev/null +++ b/examples/r/editor/about.txt @@ -0,0 +1 @@ +Editor diff --git a/examples/r/editor/app.R b/examples/r/editor/app.R new file mode 100644 index 00000000..1d8e1966 --- /dev/null +++ b/examples/r/editor/app.R @@ -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) diff --git a/src/Components/App.tsx b/src/Components/App.tsx index c9a18223..3a682e9a 100644 --- a/src/Components/App.tsx +++ b/src/Components/App.tsx @@ -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. diff --git a/src/Components/ExampleSelector.tsx b/src/Components/ExampleSelector.tsx index 06dde504..af4f9543 100644 --- a/src/Components/ExampleSelector.tsx +++ b/src/Components/ExampleSelector.tsx @@ -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]);