5

Building on multiple stackoverflow questions, I tried to build this app which contains two action buttons the first one shows a data table the second one should open another sourced app but actually, nothing changes but in the global environment all list, functions, and dataframes are reflecting. the used code.

#UI.R

library(shiny)
library(shinydashboardPlus)
library(DT)
library(readxl)
library(dplyr)
library(formattable)
library(shinydashboard)
library(shinyjqui)
library(shinyjs)
library(shinythemes)
library(markdown)

title <- "emblem"
ui = fluidPage(theme=shinytheme("superhero"),
           dashboardPage(dashboardHeader(title = title, titleWidth = 200), 
                         dashboardSidebar(selectInput("listofitems","Items List",c("Home","Group","Clients"), selected = "Home")),
                         dashboardBody(
                             useShinyjs(),
                             uiOutput("ui_myHome"))))

#SERVER.R Clientsbutton<-fluidPage(theme=shinytheme("yeti"),

                     DT::dataTableOutput("mytable"))
shinyServer(function(input, output, session){
output$mytable = DT::renderDataTable({
    mtcars
})
    output$ui_myHome<-renderUI({
        if (input$listofitems == 'Home'){(fluidPage(
            widgetUserBox(title = "Clients",
                          shiny::actionButton(inputId='clientsmainbuttonId', label="Click here"),
                          type = 2, src = "https://adminlte.io/themes/AdminLTE/dist/img/user7-128x128.jpg", color = "yellow"),
            widgetUserBox(title = "Group",
                          shiny::actionButton(inputId='GroupbuttonId', label="Click here"),
                          type = 2, src = "https://adminlte.io/themes/AdminLTE/dist/img/user7-128x128.jpg", color = "green")))}
        
        else if (input$listofitems == 'Clients'){(Clientsbutton)}
        else if (input$listofitems == 'Group'){(source("testsource.R",local = T)$value)}
    })
    observeEvent (input$GroupbuttonId,{
        #browser
        source("testsource.R",local = T)$value
    })
    observeEvent(input$clientsmainbuttonId,{updateSelectInput(session,"listofitems","Items List",         choices =c("Home","Group","Clients"), selected = "Clients")},ignoreInit = TRUE)
    observeEvent(input$logo,{updateSelectInput(session,"listofitems","Items List", choices =c("Home","Group","Clients"), selected = "Home")},ignoreInit = TRUE)
})

#TO BE SOURCED APP File name testsource.R

rm(list = ls())
library(shiny)

shinyApp(
ui=shinyUI(basicPage(
actionButton("go", "Go"),
numericInput("n", "n", 50),
plotOutput("plot")
 )),
server=shinyServer(function(input, output, session){

randomVals <- eventReactive(input$go, {
  runif(input$n)
})

output$plot <- renderPlot({
  hist(randomVals())
})
}) 
)
Ahmad
  • 274
  • 2
  • 15
John Smith
  • 278
  • 2
  • 10
  • 3
    You cannot do that, you will either need to have a separate app which then you can navigate to, or `iframe` it into the main one. Also you can create another ui within the main app. but as `runApp` is already running within the main thread in `R` you cannot start another one – Pork Chop Dec 02 '19 at 09:50
  • @Pork Chop thanks for your response, using iframe doesn't show anything just white space – John Smith Dec 02 '19 at 11:01
  • 1
    I'd use tabs, `conditionalPanel()` or simply `renderUI` to render the UI and show it when clicking a button. See also : https://shiny.rstudio.com/articles/dynamic-ui.html – Joris Meys Dec 03 '19 at 11:06
  • 2
    Nesting apps is possible with [shiny modules](https://shiny.rstudio.com/articles/modules.html). You basically just need to define the inner app as a module without parameters. – Gregor de Cillia Dec 03 '19 at 11:44
  • thanks for your responses @GregordeCillia – John Smith Dec 03 '19 at 14:30
  • @JorisMeys thank you very much – John Smith Dec 03 '19 at 14:33

0 Answers0