Скрыть и очистить selectInput

int i1 =2;
int i2=5;
double d = 3 + (double)i1/(double)i2 +2;

, если i1 / i2 будет дробным, тогда double поможет ему быть во фракции вместо int. так что теперь вы получите результат по своему усмотрению. или вы также можете использовать следующий код double d = 3+ (double) i1 / i2 + 2; В этой строке i1 преобразуется в double, который будет разделен на i2, и результат будет в два раза, поэтому результат будет равен 5.4

0
задан Stéphane Laurent 17 January 2019 в 11:15
поделиться

2 ответа

Я думаю, что понимаю. Вы можете создать реактивную переменную, которая не зависит от пользовательского интерфейса, поскольку входные данные не обновляются при удалении элемента пользовательского интерфейса.

library(shiny)
library(shinydashboard)

ui <- 
  dashboardPage(
    dashboardHeader(
      title = 'Test'),
    dashboardSidebar(),
    dashboardBody(
      selectInput(
        inputId = 'mainInput',
        label = 'Main input',
        selected = 'Show',
        choices = c('Show', 'Hide')
      ),
      uiOutput(
        outputId = 'secondInputUI'
      ),
      actionButton(
        inputId = 'thirdInput',
        label = 'Check value'
      )
    )
  )
server <- function(input, output, session){

  secondInputVar <- reactive({
    if(input$mainInput == 'Show'){
      input$secondInput
    } else {

    }
  })

  observeEvent(input$mainInput, ignoreNULL = TRUE, {
    if (input$mainInput == 'Show')
      output$secondInputUI <- 
        renderUI(
          selectInput(
            inputId = 'secondInput',
            label = 'Second input',
            selected = 0,
            multiple = FALSE,
            choices = c(1, 0)
          )
        )
    else {
      output$secondInputUI <- renderUI({
        NULL
      })
    }
  })

  observeEvent(input$thirdInput, {
    showNotification(
      session = session, 
      ui = paste(secondInputVar(), collapse = ', '))
  })
}

shinyApp(
  ui = ui,
  server = server)
0
ответ дан Alexander Leow 17 January 2019 в 11:15
поделиться

Итак, я нашел другое решение, основная идея которого заключается в следующем: обновить входное значение в обозревателе для первого ввода, скрыть второй вход от наблюдателя для второго ввода. Будет лучше, если я покажу:

ui <- 
  dashboardPage(
    dashboardHeader(
      title = 'Test'),
    dashboardSidebar(),
    dashboardBody(
      selectInput(
        inputId = 'mainInput',
        label = 'Main input',
        selected = 'Show',
        choices = c('Show', 'Hide')
      ),
      uiOutput(
        outputId = 'secondInputUI'
      ),
      actionButton(
        inputId = 'thirdInput',
        label = 'Check value'
      )
    )
)
server <- function(input, output, session){
  observeEvent(input$mainInput, {
    if (input$mainInput == 'Show')
      output$secondInputUI <- 
        renderUI(
          selectInput(
            inputId = 'secondInput',
            label = 'Second input',
            selected = 0,
            multiple = FALSE,
            choices = c(1, 0)
          )
        )
    else {
      output$secondInputUI <- 
        renderUI(
          selectInput(
            inputId = 'secondInput',
            label = 'Second input',
            selected = '',
            multiple = TRUE,
            choices = c(1, 0)
          )
        )
    }
  })

  # THE TRICK HERE ####
  observeEvent(input$secondInput, ignoreNULL = FALSE, {
    if (input$mainInput != 'Show'){
      output$secondInputUI <-
        renderUI(NULL)
    }
  })

  observeEvent(input$thirdInput, {
    showNotification(
      session = session, 
      ui = paste(input$secondInput, collapse = ', '))
  })
}

shinyApp(
  ui = ui,
  server = server)
0
ответ дан fenix_fx 17 January 2019 в 11:15
поделиться
Другие вопросы по тегам:

Похожие вопросы: