Новичок в R, теперь я работаю над блестящим приложением, которое включает в себя несколько выбранных входных данных, большинство из которых мне нужно добавить «Все», чтобы включить использование для управления целыми выходами. Но это не работает. вот кодМой запрос заключается в том, чтобы сделать обновление фрейма данных при каждом выборе соответственно, я смогу построить любые переменные
library(shiny)
library(dplyr)
library(plotly)
library(tidyverse)
brand<-mutate(mtcars,brand=substr(mtcars$model,1,4))
shinyUI(fluidPage(
titlePanel("mtcars"),
sidebarLayout(
sidebarPanel(
sliderInput("bins", "cost", min = 0,max = 10000,value = 1000),
selectInput("f1","brand",choices=unique(mtcars$m),selected = "Merc"),
selectInput("f2","model",choices=NULL),
selectInput("f3","cyl",choices= c("All",unique(mtcars$cyl)),selected = "All"),
selectInput("f4","hp",choices=c("All", unique(mtcars$hp)),selected = "All"),
selectInput("f5","vs",choices=c("All", unique(mtcars$vs)),selected = "All"),
selectInput("f6","gear",choices=c("All", unique(mtcars$gear)),selected = "All")),
mainPanel(
plotlyOutput("Test2", height = "250px"),
plotlyOutput("Test3", height = "250px")
)
)
)
server<-function(input,output,session){
observe({
print(input$brand)
df2<-brand%>%filter(brand==input$f1)
updateSelectInput(session,"f2","model",choices=unique(df2$model))
print(df2)
})
observe({
df3<-reactive({
if(input$f3=="All"){df2}
else {df3<-df2%>%filter(cyl==input$f3)
updateSelectInput(session,"f3","cyl",choices=unique(df3$cyl))}
print(df3)
})
output$plot <- renderPlotly({
plot_ly(df3, x = ~mpg, y = ~wt)
})
})}