2016-04-21 15 views
0

Ich mag würde einen Textwert für eine selectInput Funktion setzen und den Wert für jede Wahl der Auswahl speichern. Mein Versuch will nicht arbeiten, und ich kann den Grund nicht verstehen.Shiny - Update Eingabe von Text für Auswahleingang

hat jemand eine Idee?

library(shiny) 

runApp(list(
    ui = bootstrapPage(
    sidebarPanel(
     selectInput('SELoption', label = "Select option", 
        choices = c(
        "Option 1" = 'f1', 
        "Option 2" = 'f2', 
        "Option 3" = 'f3'), 
        selected = 'f1') 
), 

    mainPanel(
    textInput("text", label = strong("Text"),value = 0) 
) 

), 

server = function(input, output, session) { 
    userEnv <- new.env() 
    userEnv$text <- NULL 

    optionID <- reactive({ 
    if(is.null(input$SELoption)){return()} 
    return(input$SELoption) 
    }) 

    observe({ 
    fID <- optionID() 

    if(!is.null(userEnv$text[[fID]])) 
     updateTextInput(session, "text", value = userEnv$text[[fID]]) 
    }) 

} 
)) 

Antwort

0
library(shiny) 
library(shinyjs) 

runApp(list(
    ui = tagList(useShinyjs(),bootstrapPage(
    sidebarPanel(
     selectInput('SELoption', label = "Select option", 
        choices = c(
        "Option 1" = 'f1', 
        "Option 2" = 'f2', 
        "Option 3" = 'f3'), 
        selected = 'f1') 
    ), 

    mainPanel(
     disabled(textInput("text", label = strong("Text"),value = "f1")) 
    ) 

)), 

    server = function(input, output, session) { 


    optionID <- reactive({ 
     if(is.null(input$SELoption)){return(NULL)} 
     return(input$SELoption) 
    }) 

    observe({ 
     fID <- optionID() 

     if(!is.null(fID)) 
     updateTextInput(session, "text", value = fID) 
    }) 


    } 
)) 
+0

Danke für die Hilfe, aber dies nicht den eingestellten Wert speichert neben der Idee, eine Zahl zu setzen, obwohl ich die 'textinput' verwenden wie bei den' numericinput' können Sie nicht gesetzt arbitrarly – Stefano