Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
653 views
in Technique[技术] by (71.8m points)

r - Shiny app: nothing changes when clicking on action button

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())
})
}) 
)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...