2017-09-21 8 views
1

반짝 이는 응용 프로그램을 만들고 있습니다. 목표는 처음에는 데이터 집합에서 사용자 지정 필터를 만드는 것입니다. 해당 필터를 만든 후 selectInput 탭에서 열 중 하나의 옵션을 동적으로 변경해야합니다. 문제는 반짝이는 앱의 UI 섹션에서 새 데이터 세트를 참조 할 때 해당 데이터 프레임을 인식하지 못한다는 것입니다. 아래는 작동하는 나의 UI 및 서버 부품이지만 selectInput 값을 수동으로 추가해야합니다. 자동으로 변경되기를 원합니다.반짝이 : 자동 선택 입력 값 업데이트 이전 필터 기준

원래 응용 프로그램 :

UI

# ui.R 

library(shiny) 
shinyUI(fluidPage(
    titlePanel("Language Selection"), 
    sidebarLayout(
    sidebarPanel(
     helpText("The goal from this is to have the select tab automatically update with the language after selecting the artist"), 

     helpText("Select your artist"), 

     textInput("artistId", "Artist", value = "", width = NULL, 
      placeholder = NULL), 

     actionButton("goButton", "Submit Artist"), 

     helpText("Based on the artist you selected, now select the Language below to display the numberlist in the main panel."), 

     selectInput("selectinputid", "Language to Select:", choices = c("English" = "English", "French" = "French", "German" = "German")), 
     ##selectInput("selectinputid", "Language to Select:", choices = artist_filter_complete$Language), 
     actionButton("goButton1", "Submit Language")), 
mainPanel(
     tableOutput("result") 
    ) 
    ) 
)) 

서버 이건 내 출력 모습입니다

##server 
library(shiny) 

Artist <- c("A1", "A1", "A1", "A1", "A1", "A1", "A1", "A1", "A1", "A1", "A1", "A1", 
      "A2", "A2", "A2", "A2", "A2", "A2", "A2", "A2", "A2", "A2", "A2", "A2", 
      "A3", "A3", "A3", "A3", "A3", "A3", "A3", "A3", "A3", "A3", "A3", "A3") 

Language <- c("Spanish", "Spanish", "Spanish", "Spanish", "Spanish", "German", "German", "German", "French", "French", "French", "French", 
       "Italian", "Italian", "Italian", "Italian", "Italian", "Polish", "Polish", "Polish", "Israeli", "Israeli", "Israeli", "Israeli", 
       "English", "English", "English", "English", "English", "Armenian", "Armenian", "Armenian", "Bengali", "Bengali", "Bengali", "Bengali") 

NumberList <- c("uno", "dos", "tres", "cuatro", "cinco", "einz", "zwei", "drei", "un", "deux", "trois", "quatre", 
       "uno", "due", "tre", "quattro", "cinque", "jeden", "dwa", "trzy", "achat", "shtaim", "shalosh", "arba", 
       "one", "two", "three", "four", "five", "mek", "yerku", "yerek", "shoonno", "ek", "dui", "tin") 

df <- data.frame(Artist, Language, NumberList) 


shinyServer(function(input, output) { 
    output$result <- renderTable({ 
    randomVals <- eventReactive(input$goButton, input$artistId) 
    artist_filter <- c(randomVals()) 
    artist_filter_complete <- filter(df, Artist == artist_filter) 
    randomVals2 <- eventReactive(input$goButton1, input$selectinputid) 
    target <- c(randomVals2()) 
    result_final<-filter(artist_filter_complete, Language %in% target) 
    result_final 
    }) 
} 
) 

같은 :

enter image description here

언어를 selectInput으로 자동/동적으로 변경하려면 어떻게해야합니까? 처음에 입력 한 아티스트가 인 이 있습니까? 내 시도는 UI 부분에서 주석하지만 난 그게 호출 실행하면된다

##selectInput("selectinputid", "Language to Select:", choices = artist_filter_complete$Language), 

그것은 그 dataframe을 찾을 수 없다는 내용 : 몇 가지 버튼을

답변

4

artist_filter_complete 내가 여기 몇 가지를 변경하고 제거하는

library(shiny) 

Artist <- c("A1", "A1", "A1", "A1", "A1", "A1", "A1", "A1", "A1", "A1", "A1", "A1", 
      "A2", "A2", "A2", "A2", "A2", "A2", "A2", "A2", "A2", "A2", "A2", "A2", 
      "A3", "A3", "A3", "A3", "A3", "A3", "A3", "A3", "A3", "A3", "A3", "A3") 

Language <- c("Spanish", "Spanish", "Spanish", "Spanish", "Spanish", "German", "German", "German", "French", "French", "French", "French", 
       "Italian", "Italian", "Italian", "Italian", "Italian", "Polish", "Polish", "Polish", "Israeli", "Israeli", "Israeli", "Israeli", 
       "English", "English", "English", "English", "English", "Armenian", "Armenian", "Armenian", "Bengali", "Bengali", "Bengali", "Bengali") 

NumberList <- c("uno", "dos", "tres", "cuatro", "cinco", "einz", "zwei", "drei", "un", "deux", "trois", "quatre", 
       "uno", "due", "tre", "quattro", "cinque", "jeden", "dwa", "trzy", "achat", "shtaim", "shalosh", "arba", 
       "one", "two", "three", "four", "five", "mek", "yerku", "yerek", "shoonno", "ek", "dui", "tin") 

df <- data.frame(Artist, Language, NumberList) 

ui <- shinyUI(
    fluidPage(
    titlePanel("Language Selection"), 
    sidebarLayout(
     sidebarPanel(
     helpText("The goal from this is to have the select tab automatically update with the language after selecting the artist"), 

     helpText("Select artistId artist"), 
     selectInput("artistId", "Artist", choices = unique(df$Artist)), 
     helpText("Based on the artist you selected, now select the Language below to display the numberlist in the main panel."), 

     selectInput("selectinputid", "Language to Select:", choices = unique(df$Language)), 
     actionButton("goButton1", "Submit Language")), 
     mainPanel(
     tableOutput("result") 
    ) 
    ) 
) 
) 

server <- function(input, output,session) { 

    observeEvent(D1(),{ 
    updateSelectInput(session, "selectinputid", "Language to Select:", choices = unique(D1()$Language),selected = unique(D1()$Language)[1]) 
    }) 

    D1 <- reactive({ 
    df[df$Artist %in% input$artistId,] 
    }) 

    D2 <- eventReactive(input$goButton1,{ 
    D1()[D1()$Language %in% input$selectinputid,] 
    }) 

    output$result <- renderTable({ 
    D2() 
    }) 
} 

shinyApp(ui, server) 

편집 : 나는 자신을보고 그것이 당신에게 의미가 있는지이 생각 여기에 필요한 해달라고 요청에 의해 입력을 텍스트로 수정

,
library(shiny) 

Artist <- c("A1", "A1", "A1", "A1", "A1", "A1", "A1", "A1", "A1", "A1", "A1", "A1", 
      "A2", "A2", "A2", "A2", "A2", "A2", "A2", "A2", "A2", "A2", "A2", "A2", 
      "A3", "A3", "A3", "A3", "A3", "A3", "A3", "A3", "A3", "A3", "A3", "A3") 

Language <- c("Spanish", "Spanish", "Spanish", "Spanish", "Spanish", "German", "German", "German", "French", "French", "French", "French", 
       "Italian", "Italian", "Italian", "Italian", "Italian", "Polish", "Polish", "Polish", "Israeli", "Israeli", "Israeli", "Israeli", 
       "English", "English", "English", "English", "English", "Armenian", "Armenian", "Armenian", "Bengali", "Bengali", "Bengali", "Bengali") 

NumberList <- c("uno", "dos", "tres", "cuatro", "cinco", "einz", "zwei", "drei", "un", "deux", "trois", "quatre", 
       "uno", "due", "tre", "quattro", "cinque", "jeden", "dwa", "trzy", "achat", "shtaim", "shalosh", "arba", 
       "one", "two", "three", "four", "five", "mek", "yerku", "yerek", "shoonno", "ek", "dui", "tin") 

df <- data.frame(Artist, Language, NumberList) 

ui <- shinyUI(
     fluidPage(
       titlePanel("Language Selection"), 
       sidebarLayout(
         sidebarPanel(
           helpText("The goal from this is to have the select tab automatically update with the language after selecting the artist"), 

           helpText("Select artistId artist"), 
           textInput("artistId", "Artist", value = "", width = NULL, placeholder = NULL), 
           helpText("Based on the artist you selected, now select the Language below to display the numberlist in the main panel."), 

           selectInput("selectinputid", "Language to Select:", choices = unique(df$Language)), 
           actionButton("goButton1", "Submit Language")), 
         mainPanel(
           tableOutput("result") 
         ) 
       ) 
     ) 
) 

server <- function(input, output,session) { 

     observeEvent(D1(),{ 
       updateSelectInput(session, "selectinputid", "Language to Select:", choices = unique(D1()$Language),selected = unique(D1()$Language)[1]) 
     }) 

     D1 <- reactive({ 
       df[df$Artist %in% input$artistId,] 
     }) 

     D2 <- eventReactive(input$goButton1,{ 
       D1()[D1()$Language %in% input$selectinputid,] 
     }) 

     output$result <- renderTable({ 
       D2() 
     }) 
} 

shinyApp(ui, server) 
+0

감사합니다. 원본을 약간 변경해야 할 것 같습니다. –

+0

첫 번째가 selectInput이 아닌 textInput이되도록 수정할 수 있습니까? –

+1

거기에 모양이 있습니다. –