2016-12-23 16 views
0

入力用の送信ボタンと結果を隠す/表示するためのチェックボックスを含むShinyアプリを作成しようとしています。私の問題は、私が[Submit]ボタンをもう一度押していない限り、hide/showチェックボックスをチェックしたり、解除したりすることは効果がありません。Shiny with shinyjsの送信ボタンで結果を非表示/表示

ユーザーがチェックボックスをオンにして、送信ボタンに依存せずにチェックを外すとすぐに結果を表示するにはどうすればよいですか?それはthis質問に似ていますが、代わりにshinyjsパッケージを使用しています。

UI.R

ui <- shinyUI(fluidPage(
# Initiate shinyjs package 
useShinyjs(), 
        # Select layout type 
        sidebarLayout(
         # Sidebar content 
         sidebarPanel(
          # Input phrase1 
          textInput("phrase1", "Enter a word or phrase here", "It’s not rocket"), 
          # Input phrase2 
          textInput("phrase2", "Enter a word or phrase here", "science"), 
          # Submit button 
          submitButton("Paste phrases") 
         ), 
         # Main panel content 
         mainPanel(
          # Checkbox to show/hide results 
          checkboxInput("checkbox", "Show results?", TRUE), 
          # Results 
          textOutput("full_phrase") 
         ) 
        ) 
)) 

Server.R

server <- shinyServer(function(input, output) { 
     observe(toggle("full_phrase", condition=(input$checkbox==T))) 
     output$full_phrase <- renderText({paste(input$phrase1, input$phrase2)}) 
}) 

すべてのヘルプは大歓迎:

は、ここで問題を説明するためにいくつかのサンプルコードです!

答えて

1

あなたのsubmitButtonは、彼がクリックされるまですべての反応を停止します。 UIの要素をボタンに依存しないようにするには、代わりにactionButtonを使用し、ボタンをクリックしたときに実行するアクションにイベントオブザーバを使用する必要があります。

library(shiny) 
library(shinyjs) 

shinyApp(
    ui = 
    shinyUI(fluidPage(
     # Initiate shinyjs package 
     useShinyjs(), 
     # Select layout type 
     sidebarLayout(
     # Sidebar content 
     sidebarPanel(
      # Input phrase1 
      textInput("phrase1", "Enter a word or phrase here", "It's not rocket"), 
      # Input phrase2 
      textInput("phrase2", "Enter a word or phrase here", "science"), 
      # Submit button 
      actionButton("paste_phrase", 
         label = "Paste phrases") 
     ), 
     # Main panel content 
     mainPanel(
      # Checkbox to show/hide results 
      checkboxInput("checkbox", "Show results?", TRUE), 
      # Results 
      textOutput("full_phrase") 
     ) 
    ) 
    )), 

    server = 
    shinyServer(function(input, output, session) { 
     observe({ 
     toggle("full_phrase", 
       condition=input$checkbox) 
     }) 

     pasted_phrases <- 
     eventReactive(
      input$paste_phrase, 
      { 
      paste(input$phrase1, input$phrase2) 
      } 
     ) 

     output$full_phrase <- 
     renderText({pasted_phrases()}) 
    }) 
) 
+0

ありがとうございました! – carozimm