Joh*_*ith 5 r shiny shinydashboard reactive
基于多个 stackoverflow 问题,我尝试构建这个应用程序,其中包含两个操作按钮,第一个显示数据表,第二个应该打开另一个源应用程序,但实际上,没有任何变化,但在全局环境中,所有列表、函数和数据框都是反映。使用的代码。
#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"))))
Run Code Online (Sandbox Code Playgroud)
#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)
})
Run Code Online (Sandbox Code Playgroud)
#待获取应用程序 文件名 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())
})
})
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1124 次 |
| 最近记录: |