Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. library("shiny")
  2.  
  3. choicesONE <- c("a","b","c","d","e")
  4.  
  5. choicesTWO <- c("a","c","e")
  6.  
  7. ui <- shinyUI(fluidPage(
  8.  
  9. sidebarLayout(
  10.  
  11. sidebarPanel(
  12.  
  13. selectizeInput(inputId="topic",
  14. label = ("Topic"),
  15. choices=NULL,
  16. multiple = T,
  17. options=list(maxItems = 1,
  18. placeholder="Please choose...")),
  19.  
  20. checkboxInput("sub", "Show only subchoices", value = FALSE, width = NULL)
  21.  
  22. ),
  23.  
  24. mainPanel(
  25.  
  26. )
  27.  
  28. )
  29.  
  30. ))
  31.  
  32. server <- function(input, output, session) {
  33.  
  34. #------- Initialize the Memory ----------
  35.  
  36. choice <- reactiveValues(selection = NULL)
  37.  
  38. #------ Whenever the inputs are changed, it only modifies the memory----
  39.  
  40. observeEvent(input$topic,{
  41.  
  42. choice$selection <- input$topic
  43.  
  44. })
  45.  
  46. #------ Update UI element using the values stored in memory ------
  47.  
  48. observe({
  49.  
  50. if(input$sub==T) {
  51.  
  52. updateSelectizeInput(session,
  53. server = T,
  54. 'topic',
  55. choices = choicesTWO,
  56. selected = choice$selection)
  57.  
  58. } else {
  59.  
  60. updateSelectizeInput(session,
  61. server = T,
  62. 'topic',
  63. choices = choicesONE,
  64. selected = choice$selection)
  65.  
  66.  
  67. }
  68.  
  69.  
  70. })
  71.  
  72.  
  73.  
  74. }
  75.  
  76. shinyApp(ui = ui, server = server)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement