小编use*_*490的帖子

更改r Shiny中的选择输入选项

我正在尝试使用Shiny构建应用程序.它将包含2个下拉列表,其中一个将显示7个不同扇区的名称 - 它,银行,钢铁,fmcg等.另一个下拉列表应包含所选部门的公司名称列表,即名称列表将是动态的.

1.我不知道如何动态更改第二个下拉列表的列表,例如.如果我们选择"IT"第二个下拉列表应包含"infosys","tcs"等,如果我们选择"Bank",第二个下拉列表显示"SBI","ICICI"等.

ui.R

library(shiny)
shinyUI(fluidPage(
titlePanel("Forecasting of stock prices and their accuracies"),

sidebarLayout(
sidebarPanel(
radioButtons("rd",
             label="Select time range for training dataset",
             choices=list("23 month","18 month","12 month","6 month"),
             selected="23 months"),

selectInput("sector",
            label="select a sector",choices=list("IT"=1,"Bank"=2,"Power"=3,"Steel"=4,        
"FMCG"=5,"Infrastructure"=6,"Automobile"=7 ),                  
            selected=1),


selectInput("stock",
            label="select a option",choices=list("co.1"=1,"co.2"=2,
"co.3"=3,"co.4"=4,"co.5"=5,"
co.6"=6,"co.7"=7,"co.8"=8),
            selected=1)

),
mainPanel("Display results",
        textOutput("summary"),
        tableOutput("view"))
)
))
Run Code Online (Sandbox Code Playgroud)

server.R

shinyServer(function(input, output) {
datasetInput <- reactive({
 if(input$sector=="1"){
 switch(input$stock, 
               "1" = Infy,
               "2" = TCS,
               "3" = Wipro,
               "4" = TechM)}

 else if(input$sector=="2"){
   switch(input$stock, 
          "1" = SBIN,
          "2" = …
Run Code Online (Sandbox Code Playgroud)

r shiny

12
推荐指数
1
解决办法
2万
查看次数

标签 统计

r ×1

shiny ×1