简体   繁体   中英

R Shiny: Issue passing reactive values to module

This should be pretty easy, but it is not working as I would expect it to. All I am trying to do is get "first light" in passing reactive elements from main server function to a module. The point of this toy example is simple: user types anything in a textInput() box and that value gets displayed in two verbatimTextOutput() boxes, one from the main server, one called in the module server. I am looking for both boxes to display what the user types in, but the module box does not. This tells me that the module is not properly receiving the parameter, and I do not see my mistake. Thanks!

library(shiny)

ui <- function(request) {
    fluidPage(
        column(12, textInput("par", "Parameter", value = "")),
        column(12, parametersMDUI(0)),
        column(12, verbatimTextOutput("view", placeholder = TRUE))
          )
}

server <- function(input, output, session) {
    param <- reactive({ input$par })
    callModule(parametersMDServer, 0, param)
    output$view <- renderText({ param() })
}


parametersMDUI <- function(id) {
    ns <- NS(id)

    tags$div(
        column(12, verbatimTextOutput("symbolName", placeholder = TRUE)),
        id = ns('parametersMDui')
    )
}


parametersMDServer <- function(input, output, session, param) {
    ns = session$ns

    output$symbolName <- renderText({ param })
}

shinyApp(ui = ui, server = server, enableBookmarking = "server")

It seems like you use tags$div(..., id = "my_output_id") in your code and then try to access the div with renderUI ? This won't work. Use the "standard"

# server side
output$my_output_id <- renderUI({ ... })

# client side
uiOutput("my_output_id")

instead. Apart from that, you forgot to use the ns function in parametersMDUI . I will not post any fixed versions of your code anymore since your errors start to repeat and you really need to be able to spot them yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM