Ссылка R блестящий элемент selectInput для открытия файла actionButton - PullRequest
0 голосов
/ 19 сентября 2018

Используя R блестящий, можно ли связать элемент selectInput с кнопкой открытия файла?Я хотел бы адаптировать кнопку аргумента действия onclick для достижения этого.

Ниже приведен воспроизводимый пример:

Предположим, у нас есть "file_1.pdf" и "file_2"..pdf "в папке" www ", как мне открыть файл, соответствующий выбранному варианту ввода?

library(shinydashboard)
library(shiny)


ui <- dashboardPage(
  dashboardHeader(title = "Open file app"),
  dashboardSidebar(),
  dashboardBody(
        fluidRow(
          selectInput(inputId = "file_choice",label = "Choose the file to open",choices = c("file_1","file_2")),
          actionButton("bell","Open the selected file", class = "btn action-button",onclick = "window.open('file_1.pdf')")) #onclick argument must be adapted 
          )
)

server <- function(input, output) {}

shinyApp(ui, server)

Большое спасибо!

1 Ответ

0 голосов
/ 19 сентября 2018

Вы можете сделать

  selectInput(inputId = "file_choice", 
              label = "Choose the file to open", 
              choices = c("file_1"="Rplot01.png","file_2"="Rplot02.png")),
  actionButton("bell","Open the selected file", class = "btn action-button", 
               onclick = "window.open($('#file_choice').val())"))  

Объяснение: $(...) - селектор.$('#file_choice') выбирает элемент с идентификатором file_choice.Это selectInput$('#file_choice').val() возвращает значение выбранной опции.

...