【发布时间】:2022-01-04 18:48:39
【问题描述】:
在下面闪亮的应用程序中,我希望在第一次加载应用程序时显示图像,然后在单击 actionButton() 后隐藏。
library(shiny)
library(shinyjs)
library(shinydashboard)
library(dplyr)
# Some data
sideUI <- function(id) {
ns <- NS(id)
tagList(
actionButton(ns("action"),"Submit")
)
}
# In this case this server not needed but using uiOuput/renderUI in real case
# sideServer <- function(id) { moduleServer(id,function(input, output, session) { })}
# Define the UI and server functions for the map
sideServer <- function(id) {
moduleServer(
id,
function(input, output, session) {
return(btn = reactive(input$action))
})
}
imgUI <- function(id) {
ns <- NS(id)
tagList(
div(
id = "showimg",
img(src='apps.png', align = "center"))
)
}
textServer <- function(id, btn) {
moduleServer(
id,
function(input, output, session) {
observeEvent(btn(), {
shinyjs::hide(id = "showimg")
})
})
}
# Build ui & server and then run
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(sideUI("side")),
dashboardBody(useShinyjs(),imgUI("imgPL"))
)
server <- function(input, output, session) {
# use the reactive in another module
city_input <- sideServer("side")
textServer("imgPL", btn = city_input$btn)
}
shinyApp(ui, server)
【问题讨论】:
标签: r image shiny module shinyjs