0

I am using a modalDialog pop up to allow an issue to be recorded in the github api. However, as the actionButton("ok", "Submit new issue") is in the modularized server side code, I believe due to it not being name spaced the button does not work. I have provided a test code below which should show the title when the button is pressed but it doesn't do anything.

Is there any way around it?

library(shiny)

editTableUI <- function(id){
  ns<-NS(id)
  tagList(
    actionButton(ns("add_issue"), "New Issue"),
    textOutput("text"))
  }
  
editTable <-function(input, output, session){
  
  observeEvent(input$add_issue, {
    loginModal <- function() {
      modalDialog(
        title = "Create Issue",
        textInput("title", "Title"),
        textAreaInput("body", "Body", placeholder = "Leave a comment", width = '100%', height = '300px' ),
        selectInput("asignee",label= "Assignees", selected = NULL, choices = c("a","b","c","d"), multiple = T ),
        footer = tagList(
          modalButton("Cancel"),
          actionButton("ok", "Submit new issue")),
        fade = T,
        size = c("s")
        )
    }
    showModal(loginModal())
  })
  
  observeEvent(input$ok, {
  output$text <- renderText({ input$title })})
  
}
  

ui <- fluidPage(
  editTableUI("tab2"))
  
server <- function(input, output, session) {
  callModule(editTable, "tab2")}
  
shinyApp(ui, server)  
4
  • where the Table variable??? Commented Jan 21, 2021 at 13:03
  • I put the wrong code during the transfer, my bad. I have edited it now. Should have been textOutput("text"). @PorkChop Commented Jan 21, 2021 at 13:20
  • Again what is input$create ??? and where is it?, should that be input$ok ??? Commented Jan 21, 2021 at 13:35
  • The issue is the button. This code is to just provide an example. However, I have edited the input$ok as well thank you. @PorkChop Commented Jan 21, 2021 at 13:42

1 Answer 1

1

I see what you mean now, when you are working with modules and creating objects inside the modules, you need to assign the namespace to them e.g. session$ns("ok"), then you can access them like so: session$input$ok, similar for the title input you have, the code below should work for you...

library(shiny)

editTableUI <- function(id){
    ns <- NS(id)
    tagList(
        actionButton(ns("add_issue"), "New Issue"),
        textOutput(ns("text"))
    )
}

editTable <-function(input, output, session){
    
    observeEvent(input$add_issue, {
        loginModal <- function() {
            modalDialog(
                title = "Create Issue",
                textInput(session$ns("title"), "Title"),
                textAreaInput("body", "Body", placeholder = "Leave a comment", width = '100%', height = '300px' ),
                selectInput("asignee",label= "Assignees", selected = NULL, choices = c("a","b","c","d"), multiple = T ),
                footer = tagList(
                    modalButton("Cancel"),
                    actionButton(session$ns("ok"), "Submit new issue")),
                fade = T,
                size = c("s")
            )
        }
        showModal(loginModal())
    })
    
    observeEvent(session$input$ok, {
        output$text <- renderText({ 
            input$title 
        })
    })
    
}


ui <- fluidPage(
    editTableUI("tab2"))

server <- function(input, output, session) {
    callModule(editTable, "tab2")
    
}

shinyApp(ui, server) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.