Option 1
您可从<代码>上生成一个数据框架。 类似:
mod_dataframe_server <- function(id){
moduleServer( id, function(input, output, session){
ns <- session$ns
df <- data.frame(Years = seq(2000, 2009),
Colonne2 = rnorm(10),
Colonne3 = rnorm(10),
Colonne4 = rnorm(10))
return(df)
})
}
可在<代码>mod_button_server上查阅。 类似:
mod_button_server <- function(id){
moduleServer( id, function(input, output, session){
ns <- session$ns
observeEvent(input$button, {
df1 <- mod_dataframe_server(ns("mytable"))
output$table <- renderTable(df1)
})
})
}
在发生违约时可以中止。 圆门模板,因为没有必要。 表格的显示载于mod_button_ui
:
mod_button_ui <- function(id){
ns <- NS(id)
tagList(
actionButton(ns("button"), label = "Click"),
tableOutput(ns("table"))
)
}
服务器功能与您的尝试相同,app_ui
。 looks:
app_ui <- function(request) {
tagList(
golem_add_external_resources(),
fluidPage(
mod_button_ui("B1"),
)
)
}
Option 2
Alternatively, you could use just the button module and remove the dataframe module.
Meaning mod_button_server
would use observe()
and bindEvent()
to create and refresh the table upon pressing the button.
mod_button_ui
, app_ui
, and app_server
are the same as in the first option.
mod_button_server <- function(id){
moduleServer( id, function(input, output, session){
ns <- session$ns
df1 <- observe({
output$table <- renderTable(
data.frame(Years = seq(2000, 2009),
Colonne2 = rnorm(10),
Colonne3 = rnorm(10),
Colonne4 = rnorm(10))
)
}) |> bindEvent(input$button)
})
}
Working Example
采用上述备选办法2。 备选案文1已经列入,但我就此发表了意见。
library(shiny)
mod_dataframe_server <- function(id){
moduleServer(id, function(input, output, session) {
ns <- session$ns
df <- data.frame(Years = seq(2000, 2009),
Colonne2 = rnorm(10),
Colonne3 = rnorm(10),
Colonne4 = rnorm(10))
return(df)
})
}
mod_button_server <- function(id){
moduleServer(id, function(input, output, session) {
ns <- session$ns
# option 1
# observeEvent(input$button, {
# df1 <- mod_dataframe_server(ns("mytable"))
# output$table <- renderTable(df1)
# })
# option 2
df1 <- observe({
output$table <- renderTable(
data.frame(Years = seq(2000, 2009),
Colonne2 = rnorm(10),
Colonne3 = rnorm(10),
Colonne4 = rnorm(10))
)
}) |> bindEvent(input$button)
})
}
mod_button_ui <- function(id){
ns <- NS(id)
tagList(
actionButton(ns("button"), label = "Click"),
tableOutput(ns("table"))
)
}
app_ui <- function(request) {
tagList(
fluidPage(
mod_button_ui("B1"),
)
)
}
app_server <- function(input, output, session) {
mod_button_server("B1")
}
shinyApp(
ui = app_ui,
server = app_server
)