Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Shiny中自定义fluidRow_R_Shiny_Shinydashboard - Fatal编程技术网

如何在Shiny中自定义fluidRow

如何在Shiny中自定义fluidRow,r,shiny,shinydashboard,R,Shiny,Shinydashboard,所以我尝试创建这个输出,但是在仪表板形式中使用Shiny。应该注意的是,这是我第二周使用Shiny,所以我非常缺乏经验 这是我的密码: library(shiny) library(shinydashboard) library(ggplot2) library(dplyr) library(gapminder) gm <- gapminder gm <- transform(gm, pop = as.numeric(pop)) cgm <- gm %>% gr

所以我尝试创建这个输出,但是在仪表板形式中使用Shiny。应该注意的是,这是我第二周使用Shiny,所以我非常缺乏经验

这是我的密码:

library(shiny)
library(shinydashboard)
library(ggplot2)
library(dplyr)
library(gapminder)


gm <- gapminder 
gm <- transform(gm, pop = as.numeric(pop))

cgm <- gm %>% group_by(continent,year) %>% summarise(totpop=sum(pop),avglifeExp=sum(pop*lifeExp)/totpop,avggdpPercap=sum(pop*gdpPercap)/totpop, numCountries=n())

body <- dashboardBody(

    fluidRow(

     tabBox(
      title = "Population",
      id = "proj", width=12,      
      tabPanel("Visualization", plotOutput("ggp"),    
      tabPanel("GapMinder Data", dataTableOutput("table")),
      tabPanel("Aggregated GapMinder Data", dataTableOutput("table1"))
    )

  )
),
    fluidRow(sliderInput("slider1", label = h3("Year"), min = 1952, 
        max = 2007, value = 1952, step = 5, sep ="", width="100%"))
)

# This is UI, it has a clean look because we defined body up above. 
ui <- dashboardPage(
    dashboardHeader(title = "Module 2"),
    dashboardSidebar(
        helpText("GapMinder Data: Worldwide average life expectancy, population and GPD per Capita 1952-2007"),
        menuItem),
    body
  )

# This is server function is the same as in the layout practice. 
server <- function(input, output) {

      output$tabPanelSelected <- renderText({
        input$proj

      })

      output$ggp <- renderPlot({ 

          p <- ggplot(data=subset(gm, year==input$Year), aes(x=lifeExp)) +  geom_density(alpha=.2, fill="red") + xlab("Life Expectancy")

          q <- ggplot(data=subset(cgm,year==input$Year), aes(x=continent, y=totpop, fill=continent)) + geom_bar(stat="identity")            

          r <- ggplot(data=subset(cgm,year==input$Year), aes(x=continent, y=avggdpPercap, fill=continent)) + geom_bar(stat="identity")  
      print(p)
      print(q)
      print(r)   
  })

    output$table <- renderDataTable({gm})
    output$table1 <- renderDataTable({cgm})
}

shinyApp(ui=ui, server=server)
库(闪亮)
图书馆(shinydashboard)
图书馆(GG2)
图书馆(dplyr)
图书馆(gapminder)

gm参考您的上图,我修改了您的代码以获得类似的表示

library(shiny)
library(shinydashboard)
library(ggplot2)
library(dplyr)
library(gapminder)


gm <- gapminder 
gm <- transform(gm, pop = as.numeric(pop))

cgm <- gm %>% group_by(continent,year) %>% summarise(totpop = sum(pop),avglifeExp = sum(pop*lifeExp)/totpop,avggdpPercap = sum(pop*gdpPercap)/totpop, numCountries=n())


# This is UI, it has a clean look because we defined body up above. 
ui <- dashboardPage(
  dashboardHeader(title = "Module 2"),

  dashboardSidebar(
    helpText("GapMinder Data: Worldwide average life expectancy, population and GPD per Capita 1952-2007")
    ),

  dashboardBody(

  #  fluidRow(
      # 
      # tabBox(
      #   title = "Population",
      #   id = "proj",      
        tabPanel("Visualization",
                 fluidRow(
                   column(4,
                          plotOutput("ggp")),
                   column(4,
                          plotOutput("ggp2")),
                   column(4,
                          plotOutput("ggp3"))

                 )
                 #tabPanel("GapMinder Data", dataTableOutput("table")),
                 #tabPanel("Aggregated GapMinder Data", dataTableOutput("table1"))
      #   )
      #   
      # )
    ),
    fluidRow(sliderInput("slider1", label = h3("Year"), min = 1952, 
                         max = 2007, value = 1952, step = 5, sep = "", width="100%"))
  )
)

# This is server function is the same as in the layout practice. 
server <- function(input, output, session) {
  session$onSessionEnded(stopApp)
  # output$tabPanelSelected <- renderText({
  #   input$proj
  #   
  # })

  output$ggp <- renderPlot({ 

    ggplot(data = subset(gm, year = input$Year), aes(x = lifeExp)) +  geom_density(alpha = 0.2, fill = "red") + xlab("Life Expectancy")
  })
  output$ggp2 <- renderPlot({
    ggplot(data = subset(cgm,year = input$Year), aes(x = continent, y = totpop, fill = continent)) + geom_bar(stat = "identity")            
  })
  output$ggp3 <- renderPlot({
    ggplot(data = subset(cgm,year = input$Year), aes(x = continent, y = avggdpPercap, fill = continent)) + geom_bar(stat = "identity")  
    # print(p)
    # print(q)
    # print(r)   
  })

  #output$table <- renderDataTable({gm})
  #output$table1 <- renderDataTable({cgm})
}

shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(shinydashboard)
图书馆(GG2)
图书馆(dplyr)
图书馆(gapminder)

非常感谢你!如果我再遇到错误,我会插话的。自从这个项目以来,由于教程的帮助,我已经走了很长的路。