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

inputID containing a "-" fails to render UI editor #8

Open
AARON-CLARK opened this issue May 1, 2023 · 4 comments
Open

inputID containing a "-" fails to render UI editor #8

AARON-CLARK opened this issue May 1, 2023 · 4 comments

Comments

@AARON-CLARK
Copy link

AARON-CLARK commented May 1, 2023

Hi, nice package! I was looking to include your pkg's markdown editor in my shiny app which leverages shiny modules, but it won't render because mdInput() seems to be quite sensitive to hyphens. This is problematic because modules leverage hyphens a ton for namespacing purposes.

Here is a minimal example:

Nothing renders.

library(shiny)
library(shinymarkdown)
ui <- fluidPage(
  mdInput(inputId = "editor-1")
)

server <- function(input, output, session) {}

shinyApp(ui, server)

Here is a shiny modules example:

Note, NS() just concatenates the id arg onto the inputID text string, separated by a hypen. So in this case, it should create an input called "my_namespace-editor".

library(shinymarkdown)
library(shiny)
modUI <- function(id) {
  mdInput(inputId = NS(id, "editor"))
}
modServer <- function(id) {
  server <- function(input, output, session) {
    observe({print(input$editor1_markdown)}) # Print the Markdown
    observe({print(input$editor1_html)}) # Print the HTML
  }
}
ui <- fluidPage(
  modUI ("my_namespace")
)
server <- function(input, output, session) {
  modServer ("my_namespace")
}
shinyApp(ui, server)
@AARON-CLARK
Copy link
Author

Hi @jdtrat, is this package still actively maintained? Or should I give up on this issue? Thanks! Just want to temper my expectations.

@jcrodriguez1989
Copy link

Hi @AARON-CLARK ,
I needed to add a markdown input to my Shiny app, and found this great package. Unfortunately, it seems to be no longer maintained, so I forked it and placed some updates. You can find the {shinymarkdown} I am working on at https://github.com/jcrodriguez1989/shinymarkdown/ where I added the fix to be able to use - in the inputId (as used by Shiny namespaces).
Install the package with remotes::install_github("jcrodriguez1989/shinymarkdown").
And here are the working examples of your provided examples:

### Example 1
library(shiny)
library(shinymarkdown)

ui <- fluidPage(
  useShinyMarkdownEditor(),
  markdownEditorInput(inputId = "editor-1")
)

server <- function(input, output, session) {}

shinyApp(ui, server)


### Example 2
library(shinymarkdown)
library(shiny)
modUI <- function(id) {
  markdownEditorInput(inputId = NS(id, "editor"))
}
modServer <- function(id) {
  moduleServer(id, function(input, output, session) {
    observe({print(input$editor)})
  })
}
ui <- fluidPage(
  useShinyMarkdownEditor(),
  modUI ("my_namespace")
)
server <- function(input, output, session) {
  modServer ("my_namespace")
}
shinyApp(ui, server)


### Example 3
library(shinymarkdown)
library(shiny)
modUI <- function(id) {
  tagList(
    actionButton(NS(id, "reset"), "Reset"),
    markdownEditorInput(inputId = NS(id, "editor"))
  )
}
modServer <- function(id) {
  moduleServer(id, function(input, output, session) {
    observeEvent(input$reset, updateMarkdownEditorInput(session, session$ns("editor"), ""))
    observe({print(input$editor)})
  })
}
ui <- fluidPage(
  useShinyMarkdownEditor(),
  modUI ("my_namespace"),
  modUI ("my_namespace_2")
)
server <- function(input, output, session) {
  modServer ("my_namespace")
  modServer ("my_namespace_2")
}
shinyApp(ui, server)

@jdtrat , please let me know if you want me to create a PR from my fork to your original repo, or if it is OK for me to keep working on my fork.

@aclark02-arcus
Copy link

aclark02-arcus commented Aug 30, 2024

@jdtrat , please let me know if you want me to create a PR from my fork to your original repo, or if it is OK for me to keep working on my fork.

Awesome! I will check it out. I know it's not my place, but please keep working on your fork! 🤣

@aclark02-arcus
Copy link

@jcrodriguez1989, Do you have any plans to push your package to CRAN? Not a requirement, but would be helpful & more accessible to more R users.

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

No branches or pull requests

3 participants