ऐप काम कर रहा है, लेकिन मॉड्यूल में आउटपुट नहीं दिख रहा है। इस उदाहरण में, sumUI
और sumSE
मॉड्यूल में textOutput
काम नहीं करता है। मैंने मुख्य सर्वर में प्रतिक्रियाशील के समान तर्क का उपयोग करने का प्रयास किया। उदाहरण के लिए, input$var
sumSE में जैसे input$select_data
मुख्य सर्वर में। चीजें मुख्य सर्वर में काम करती हैं, लेकिन मॉड्यूल सर्वर में काम नहीं करती हैं। क्या कोई कारण है?
library(shiny)
sumUI <- function(id, df) {
tagList(
fluidRow(column(4, selectInput(NS(id, "var"), "Variable", choices = names(df())),
textOutput(NS(id, "test")))))
}
sumSE <- function(id, df) {
moduleServer(id, function(input, output, session) {
data <- reactive(df()[[input$var]])
output$test <- renderPrint({
data()
})
})
}
list_data <- tibble::lst(islands, iris, mtcars)
ui <- function(request){
fluidPage(
selectInput("select_data", "Select Data", choices = c(" ", names(list_data))),
actionButton("add", "Add New"),
verbatimTextOutput("output_text"),
div(id = "add_here")
)
}
server <- function(input, output, session) {
add_id <- reactiveVal(0)
df <- reactive(
get(input$select_data)
)
output$output_text <- renderPrint({
input$select_data
})
observeEvent(input$add, {
sumSE(id = paste0("hist_", input$add+add_id()), df = df)
insertUI(selector = "#add_here", ui = sumUI(paste0("sum_", input$add+add_id()), df = df))
})
}
shinyApp(ui, server)
0
Typer Writer
10 सितंबर 2021, 19:34
आह, यह समझ में आता है। मैंने आईडी को मिलाया!
– Typer Writer
10 सितंबर 2021, 19:47
1 उत्तर
सबसे बढ़िया उत्तर
library(shiny)
sumUI <- function(id, df) {
tagList(
fluidRow(column(4, selectInput(NS(id, "var"), "Variable", choices = names(df())),
textOutput(NS(id, "test")))))
}
sumSE <- function(id, df) {
moduleServer(id, function(input, output, session) {
data <- reactive(df()[[input$var]])
output$test <- renderPrint({
data()
})
})
}
list_data <- tibble::lst(islands, iris, mtcars)
ui <- function(request){
fluidPage(
selectInput("select_data", "Select Data", choices = c(" ", names(list_data))),
actionButton("add", "Add New"),
verbatimTextOutput("output_text"),
div(id = "add_here")
)
}
server <- function(input, output, session) {
add_id <- reactiveVal(0)
df <- reactive({
req(input$select_data != " ")
get(input$select_data)
})
output$output_text <- renderPrint({
input$select_data
})
observeEvent(input$add, {
sumSE(id = paste0("hist_", input$add+add_id()), df = df)
insertUI(selector = "#add_here", ui = sumUI(paste0("hist_", input$add+add_id()), df = df))
})
}
shinyApp(ui, server)
2 चीजें हैं।
- UI और सर्वर के लिए आपकी आईडी समान होनी चाहिए।
- आपको
df <- reactive(...
में खाली मानों को रोकने की आवश्यकता है, अन्यथा यदि आप ऐप शुरू होने के ठीक बादadd
पर क्लिक करते हैं तो यह ऐप को क्रैश कर देगा।
1
lz100
11 सितंबर 2021, 00:21