Quero criar um aplicativo brilhante modularizado que inicialmente exibirá texto, mas o ocultará após clicar em actionButton(). Agora o texto sempre permanece. Meu código:
(aplicativo R)
library(shiny)
library(shinyjs)
library(shinydashboard)
library(shinyWidgets)
library(dplyr)
# Load the modules
source("sideUI.R")
source("sideServer.R")
source("textUI.R")
source("textServer.R")
# Build UI & server and then run the app
ui <- dashboardPage(
dashboardHeader(title = "Text Hiding Example"),
dashboardSidebar(sideUI("side")), # Sidebar with the action button
dashboardBody(
useShinyjs(), # Initialize shinyjs
textUI("textPL") # Text UI module
)
)
server <- function(input, output, session) {
# Use the reactive in another module
btn_input <- sideServer("side")
textServer("textPL", btn = btn_input$btn)
}
shinyApp(ui, server)
textoUI.R
textUI <- function(id) {
ns <- NS(id)
tagList(
div(
id = ns("showtext"),
p("This text will be hidden after clicking the button", style = "font-size: 16px; text-align: center;")
)
)
}
textServer.R
textServer <- function(id, btn) {
moduleServer(
id,
function(input, output, session) {
ns <- session$ns # Namespace function
# Observe button click event
observeEvent(btn(), {
shinyjs::hide(ns("showtext")) # Hide the text with correct namespace
})
}
)
}
ladoUI.R
sideUI <- function(id) {
ns <- NS(id)
tagList(
actionButton(ns("action"), "Hide Text")
)
}
servidor lateral.R
sideServer <- function(id) {
moduleServer(
id,
function(input, output, session) {
return(btn = reactive(input$action)) # Return the button input as reactive
}
)
}
app.R
, você deve passar apenasbtn_input
, em vez debtn_input$btn
para atextServer()
função.Especificamente:
textServer.R
, você não deve envolver"showtext"
emns()
.Especificamente: