I have a simplified version of a shiny application I developed. What I want is to be able to show dataframe1 when Frame1 actionbutton is pressed and hide dataframe2 and again show dataframe2 when Frame2 actionbutton is pressed and hide dataframe1. I need to print the tables at the same location obviously. Thanks for any help and for your time.
server.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")
})
})
ui.R
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"))
)
)
)
)
Turns out as @Dean Attali pointed out kindly, the functions were using the same namespace with some other package which in turn rendered them not doing their function.
Using shinyjs::show(); shinyjs::hide()
solved the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With