【问题标题】:How to pass multiple variable from ui.r to server.r in shiny app in a reactive manner如何以反应方式在闪亮的应用程序中将多个变量从 ui.r 传递到 server.r
【发布时间】:2017-05-31 06:44:53
【问题描述】:

ui.r
这主要是为了分析一个商店每天的销售额

   shinyUI(fluidPage(
          titlePanel("Sales Analysis"),
          sidebarLayout(
            sidebarPanel(
              helpText("Create line graph for  
                       Sale."),
              selectInput(multiple='TRUE' ,"var", 
                          label = "Choose a year to display",
                          choices = c(Result),
                          selected = "Result[1]",
           selectInput( "var2", 
            label1 = "Choose a month to display",
            choices1 = c(Result2),
            selected1 = "Result2[1]")),
            mainPanel(
              plotOutput("lineplot"),
              print(Result),
              print(Result1)
            )
          )
        ))

服务器.r

这主要是对一家商店每天的销售额进行数据分析 使用闪亮的网络应用程序,所以我想要的是在 ui.r 中有多个下拉框,想要根据要选择的另一个下拉列表选择一个下拉列表,然后将这些选定的下拉变量传递给 server.r 在哪里它应该在查询中以反应方式传递。

library(shiny)library for shiny web browser
library(DBI) database package
library(rJava)for connection basic package
library(RJDBC) 
library(scales)
library(ggplot2)
library(PKI)
library(RCurl)
library(rsconnect)

shinyServer(function(input, output) {

  output$lineplot <- renderPlot({ 

    jcc = JDBC("","")
    conn = dbConnect(jcc,"//",user="",
                     password="")
    Result<-dbGetQuery(conn,statement = paste("select sale_dt,count(trd) as Bill from retail_str_sales_master where year(sale_date)=",input$var," group by sale_date"))
    Result$SALE_DATE<-as.Date(Result$SALE_Dt)
    #Result1<-dbGetQuery(conn,statement = paste("select sale_dt,count(trd) as Bill from retail_str_sales_master where to_char(to_date(month(sale_date),'MM'),'Month')=",input$var,"  group by sale_date"))

  draw the line Graph with the specified number of bins using Sale date and Total no Of Bills
    ggplot(Result,aes(x=SALE_DATE,y=BILL))+geom_line()+geom_point()+scale_x_date(date_breaks ="2 day", date_labels=("%d-%m-%y"))+
      scale_y_continuous(breaks =seq (0,max(Result$BILL),200))+ylab("Total No Of Bills")+xlab("sale date")+theme_bw()+
      theme(axis.text.x=element_text(angle=90))+theme(axis.text.x = element_text(vjust = 0.5,hjust = 0.5))


  })

})

【问题讨论】:

    标签: r ggplot2 shiny


    【解决方案1】:

    您可以使用renderUI()。这是一个例子:http://shiny.rstudio.com/gallery/dynamic-ui.html

    【讨论】:

    • 问题是我已经使用查询来获取 UI 部分中的值。对于单年值,图表出来很好。但是因为我需要根据年份选择月份,然后将值传递给查询中的服务器,这是无法正常工作的地方我无法在查询中的 where 条件中传递两个变量以使图形动态化。
    【解决方案2】:

    修复缩进错误并检查问题是否仍然存在。

     shinyUI(fluidPage(
      titlePanel("Sales Analysis"),
      sidebarLayout(
        sidebarPanel(
          helpText("Create line graph for  
                           Sale."),
          selectInput(multiple='TRUE' ,"var", 
                      label = "Choose a year to display",
                      choices = c(Result),
                      selected = Result[1]),
          selectInput( "var2", 
                       label1 = "Choose a month to display",
                       choices1 = c(Result2),
                       selected1 = Result2[1])
        ),
        mainPanel(
          plotOutput("lineplot"),
          print(Result),
          print(Result1)
        )
      )
    ))
    

    【讨论】:

      猜你喜欢
      • 2017-03-06
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-12
      • 1970-01-01
      • 2017-03-10
      • 2017-02-21
      相关资源
      最近更新 更多