我有一个我开发的闪亮应用程序的简化版本。我想要的是能够在按下 Frame1 动作按钮时显示 dataframe1 并隐藏 dataframe2 并在按下 Frame2 动作按钮时再次显示 dataframe2 并隐藏 dataframe1。我显然需要在同一位置打印表格。感谢您的帮助和您的时间。
服务器.R
shinyServer(function(input, output, session) {
data_for_use <- reactiveValues(d=NULL)
observeEvent(input$actForFrame1,{
data_for_use$dataFrame1 <- data.frame(firstColumn= c(1,3,5),secondColumn=c(2,4,6))})
observeEvent(input$actForFrame2,{
data_for_use$dataFrame2 <- data.frame(firstColumn= c(10,30,50),secondColumn=c(20,40,60))})
output$dataFrame1 <- DT::renderDataTable({
DT::datatable(data_for_use$dataFrame1)
})
output$dataFrame2 <- DT::renderDataTable({
DT::datatable(data_for_use$dataFrame2)
})
observeEvent(input$actForFrame1,{
show("dataFrame1")
hide("dataFrame2")
})
observeEvent(input$actForFrame2,{
show("dataFrame2")
hide("dataFrame1")
})
})
用户界面
library(shinyjs)
library(shiny)
library(DT)
shinyUI(pageWithSidebar(
headerPanel("Test"),
sidebarPanel(
actionButton("actForFrame1", "Frame1"),
actionButton("actForFrame2", "Frame2")
),
mainPanel(
useShinyjs(),
wellPanel("Test",
conditionalPanel(condition = "input.actForFrame1",
DT::dataTableOutput("dataFrame1")
),
conditionalPanel(condition= "input.actForFrame2",
DT::dataTableOutput("dataFrame2"))
)
)
)
)