R 闪亮:在多个选项卡中重新使用同一绘图不起作用

R 闪亮:在多个选项卡中重新使用同一绘图不起作用,r,shiny,shinydashboard,rpivottable,R,Shiny,Shinydashboard,Rpivottable,我正在尝试创建一个有两个选项卡的闪亮仪表板 第一个选项卡(称为:dashboard)显示两个图形,另一个选项卡(称为:widgets)用于显示第一个选项卡(称为:mpg)中的第一个图形,下面是rpivottable 问题是,当我将graphs/rpivottable添加到第二个选项卡时,所有的图都消失了 我想,当我去掉第二个选项卡的内容时,仪表板就会开始显示第一个选项卡的内容。你知道为什么会发生这种情况,以及如何解决它吗 示例代码: library(shiny) library(shinydas

我正在尝试创建一个有两个选项卡的闪亮仪表板

第一个选项卡(称为:
dashboard
)显示两个图形,另一个选项卡(称为:
widgets
)用于显示第一个选项卡(称为:
mpg
)中的第一个图形,下面是rpivottable

问题是,当我将graphs/rpivottable添加到第二个选项卡时,所有的图都消失了

我想,当我去掉第二个选项卡的内容时,仪表板就会开始显示第一个选项卡的内容。你知道为什么会发生这种情况,以及如何解决它吗

示例代码:

library(shiny)
library(shinydashboard)
library(rhandsontable)
library(writexl)
library(readxl)
library(stringr)
library(ggplot2)
library(rpivotTable)

ui <- dashboardPage(skin = 'green',

  dashboardHeader( title = "Test", titleWidth = 280),
  dashboardSidebar(width = 280,  
  sidebarMenu(
  menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
  menuItem("Pivot", tabName = "widgets", icon = icon("th"))

  )),

  dashboardBody(
  tabItems(
  # First tab content
  tabItem(tabName = "dashboard",
  fluidRow(
  column(5, 'Mpg Table') ), 
  br(), 
  fluidRow(
  rHandsontableOutput ('mpg')),
  br(),
  fluidRow(
  column(5,'mtcars Summary')),
  br(),
  fluidRow(
  column(3),column(6, tableOutput ('mtcars')),column(3))

  ),
  # Second tab content
  tabItem(tabName = "widgets",
  fluidRow(
  column(5,'Mpg table')),

  br(),

  fluidRow(
  rHandsontableOutput ('mpg')),

  br(),

  fluidRow(
  rpivotTableOutput('pivot')  
  )

  )
    )
      )
        )

server <- shinyServer(function(input, output) {

  #mpg
  output$mpg <- renderRHandsontable ({ rhandsontable({
   mpg[1,]  })
    })

  #mtcars

  output$mtcars <-renderTable ({  
   head(mtcars)})

 # pivot table

  output$pivot <- renderRpivotTable({ rpivotTable(mtcars)})


})

shinyApp(ui, server)
library(shiny)
library(shinydashboard)
library(rhandsontable)
library(writexl)
library(readxl)
library(stringr)
library(ggplot2)
library(rpivotTable)

ui <- dashboardPage(skin = 'green',
                    dashboardHeader(title = "Test", titleWidth = 280),
                    dashboardSidebar(width = 280,  
                                     sidebarMenu(
                                       menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
                                       menuItem("Pivot", tabName = "widgets", icon = icon("th"))
                                     )),
                    dashboardBody(
                      tabItems(
                        # First tab content
                        tabItem(tabName = "dashboard",
                                fluidRow(
                                  column(5, 'Mpg Table') ), 
                                br(), 
                                fluidRow(
                                  rHandsontableOutput ('mpg1')),
                                br(),
                                fluidRow(
                                  column(5, 'mtcars Summary')),
                                br(),
                                fluidRow(
                                  column(3),
                                  column(6, tableOutput ('mtcars')),column(3))
                        ),
                        # Second tab content
                        tabItem(tabName = "widgets",
                                fluidRow(
                                  column(5,'Mpg table')),
                                br(),
                                fluidRow(
                                  rHandsontableOutput ('mpg2')),
                                br(),
                                fluidRow(
                                  rpivotTableOutput('pivot'))
                                )
                        )
                      )
                    )

server <- shinyServer(function(input, output) {
  #mpg
  output$mpg1 <-output$mpg2<- renderRHandsontable ({
    rhandsontable({
      mpg[1,]})
    })
  #mtcars
  output$mtcars <-renderTable ({
    head(mtcars)})
  # pivot table
  output$pivot <- renderRpivotTable({rpivotTable(mtcars)})
})

shinyApp(ui, server)
库(闪亮)
图书馆(shinydashboard)
图书馆(rhandsontable)
图书馆(writexl)
图书馆(readxl)
图书馆(stringr)
图书馆(GG2)
图书馆(rpivotTable)
ui简单示例:

library(shiny)
library(shinydashboard)
ui <- dashboardPage(skin = 'green',

                    dashboardHeader( title = "Test", titleWidth = 280),
                    dashboardSidebar(width = 280,  
                                     sidebarMenu(
                                       menuItem(text = "Dashboard", tabName = "dashboard", icon = icon("dashboard")),
                                       menuItem(text = "Pivot", tabName = "widgets", icon = icon("th"))

                                     )),

                    dashboardBody(
                      tabItems(
                        # First tab content
                        tabItem(tabName = "dashboard",
                                fluidRow(
                                  column(5, 'Mpg Table') ), 
                                br(), 

                                fluidRow(column(width = 12, plotOutput("plot1")
                                                )
                                                        )),
                        # Second tab content
                        tabItem(tabName = "widgets",
                                fluidRow(
                                  column(5,'Mpg table')),

                                br(),

                                fluidRow(column(width = 6, plotOutput("plot2")),
                                        column(width = 6, plotOutput("plot3"))
                                ),
                                br(),
                                fluidRow(column(width = 12, plotOutput("plot4"))
                                         )
                      )
                    )
)
)

server <- shinyServer(function(input, output) {

  output$plot1 <- renderPlot({
    hist(rnorm(1000))
  })
  output$plot2 <- renderPlot({
    plot(rnorm(1000), rnorm(1000))
  })
  output$plot3 <- renderPlot({
    boxplot(rnorm(100))
  })
  output$plot4 <- renderPlot({
    ts.plot(rnorm(100))
  })
})

shinyApp(ui, server)
库(闪亮)
图书馆(shinydashboard)

ui不能重复使用同一id绑定多个输出()。因此,一个选项是在两个选项卡中为
mpg
表提供一个唯一的id,并在服务器中使用:
output$mpg1正常绘图可以工作,我注意到,但我需要rpivottable作为演示的一部分。当我补充这一点时,一切都不起作用