我试图获取server.R中的单选按钮值,并在获取值后,想要根据所选的单选按钮值执行一些过滤器。 代码如下:
library(shiny)
library(shinydashboard)
library(dplyr)
library(plyr)
library(highcharter)
shinyUI(
dashboardPage(skin = "black",
dashboardHeader(title = img(src='BoA.png',height= 60,align =
'middle')),
dashboardSidebar(
sidebarMenu(
id ="tabs",
menuItem("Block Trade",icon = icon("bank"),tabName = "blocktrade")
)
),
dashboardBody(
tabItems(
tabItem(
"blocktrade",tabBox(
id="tabset1",height = "475px",width = "1050px",
tabPanel("VOLUME BY CLIENT/STATUS",
column(width = 12,
fluidRow(
box(width = 8,highchartOutput("block_trade_hcontainer1",height = "400px",width = "400px")),
box(width = 4,title = "Status",radioButtons("status",label = NULL ,choices = c("Amended"="Amended","New"="New"),selected = "Amended",inline = TRUE))
)
)
)
)
)
)
)
)
)
library(shiny)
library(shinydashboard)
library(highcharter)
library(dplyr)
library(plyr)
library(xlsx)
block_trade<-read.xlsx('Blocktrade.xlsx',1)
shinyServer(function(input,output){
nStatus<-reactive({input$status})
block_trade<-block_trade[block_trade$Status == nStatus(),]
block_trade_volume_by_client<-data.frame(table(block_trade$Associated.Client))
output$block_trade_hcontainer1<-renderHighchart({
highchart()%>%
hc_chart(type="column")%>%
hc_xAxis(categories=block_trade_volume_by_client$Var1)%>%
hc_add_series(name="Quantity",data=block_trade_volume_by_client$Freq)%>%
hc_exporting(enabled=TRUE)
})
})
因此,在服务器端,我无法获得radiobutton值来过滤块交易数据。
答案 0 :(得分:0)
我稍微调整了你的反应函数,因为它只是在监听输入$ status,这已经是&#34;被动&#34;值。所以我将block_trade
和block_trade_volume_by_client
移到了被动反应中。因此,每当您更改input$status
时,都会相应地过滤数据。
在renderHighchart函数中,您使用nStatus <- block_trade_volume_by_client()
调用过滤后的数据。
library(shiny)
library(shinydashboard)
library(dplyr)
library(plyr)
library(highcharter)
library(xlsx)
ui <- {shinyUI(
dashboardPage(skin = "black",
dashboardHeader(title = img(src='BoA.png',height= 60,align =
'middle')),
dashboardSidebar(
sidebarMenu(
id ="tabs",
menuItem("Block Trade",icon = icon("bank"),tabName = "blocktrade")
)
),
dashboardBody(
tabItems(
tabItem(
"blocktrade",tabBox(
id="tabset1",height = "475px",width = "1050px",
tabPanel("VOLUME BY CLIENT/STATUS",
column(width = 12,
fluidRow(
box(width = 8,highchartOutput("block_trade_hcontainer1",height = "400px",width = "400px")),
box(width = 4,title = "Status",radioButtons("status",label = NULL ,choices = c("Amended"="Amended","New"="New"),selected = "Amended",inline = TRUE))
)
)
)
)
)
)
)
)
)}
block_trade<-read.xlsx('Blocktrade.xlsx',1)
server <- shinyServer(function(input,output){
nStatus<-reactive({
req(input$status)
block_trade<-block_trade[block_trade$Status == input$status,]
block_trade_volume_by_client<-data.frame(table(block_trade$Associated.Client))
block_trade_volume_by_client
})
output$block_trade_hcontainer1<-renderHighchart({
req(input$status)
block_trade_volume_by_client <- nStatus()
highchart()%>%
hc_chart(type="column")%>%
hc_xAxis(categories=block_trade_volume_by_client$Var1)%>%
hc_add_series(name="Quantity",data=block_trade_volume_by_client$Freq)%>%
hc_exporting(enabled=TRUE)
})
})