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

Make 'continue' button customisable in sub-topics #777

Merged
merged 7 commits into from
Jul 21, 2023

Conversation

dave-mills
Copy link
Contributor

Customise 'continue' button text

This PR adds the ability to specify custom 'continue' button text for each subtopic with a data-continue-text attribute. It uses the same syntax as for adding the progressive reveal option to individual topics:

### Subtopic Heading {data-continue-text: "Show Next Section"}

Any subtopics without this attribute will still use the default "Continue" text, as defined by the translation files.

Rationale

We use learnr a lot for writing interactive modules for online or mixed-learning R, statistics and data management courses. Often, we use progressively revealed subtopics for self-assessed quizzes, and we wanted a way to replace the 'Continue' text with e.g. "Show Solution", or "Next Question". I made a hack-y version for us with a custom JavaScript file, but I thought it'd be nicer to have a built-in option.

Concerns

I understand that this may be a very niche feature, so you may not want to include it for that reason. I also realise that the custom text is not translatable with this setup, but given that each document only uses 1 language at a time right now, I figured that making the custom text translatable wasn't vital. But if/when learnr is updated to allow multiple languages at the same time this would need fixing.

PR task list:

  • Update NEWS
  • Add tests (if possible)
  • Update documentation with devtools::document()

(btw - I didn't know if/how this could be testable. I'm not very familiar with R package development, so happy to add tests if needed or tidy up other package-dev things!)

Thanks for your time, and thanks for such a great package for building training resources!

@CLAassistant
Copy link

CLAassistant commented Apr 4, 2023

CLA assistant check
All committers have signed the CLA.

@dave-mills
Copy link
Contributor Author

Example of an Rmd file with this feature:

---
title: "Example custom button text"
output:
  learnr::tutorial:
    progressive: yes
runtime: shiny_prerendered
description: Example learnr tutorial with custom continue buttons
---

```{r setup, include=FALSE}
library(learnr)
```

## Topic 1

### Question 1 {data-continue-text="Show Solution"}

Question text goes here.

### Solution 1 {data-continue-text="Next Question"}

Solution text goes here.

### Question 2 {data-continue-text="Show Solution"}

Question 2 text.

### Solution 2

The next button has the 'default' text for your langauge.

## Topic 2

etc...

Copy link
Member

@gadenbuie gadenbuie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I refactored the code slightly and added a manual test. Overall this looks great! It'd be nice to have this documented somewhere in the learnr website, but I can add that later before the next CRAN release.

@gadenbuie gadenbuie merged commit eb45549 into rstudio:main Jul 21, 2023
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants