2016-04-21 125 views
0

我想爲selectInput函數設置文本值併爲選擇的每個選項保存值。我的嘗試不想工作,我不明白原因。閃亮 - 爲選擇輸入更新輸入文本

有沒有人有想法?

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]]) 
    }) 

} 
)) 

回答

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

感謝您的幫助,但除了這個想法是設置了一些即使我使用'textinput'作爲與'numericinput'您不能設置arbitrarly這不保存設定值 – Stefano