2017-09-04 5 views
3

私は、スライドバーでフォントのスケーリングを選択的に制御したいと考えています。これは可能ですか?Rの反応的なCSSプロパティSh​​iny

私は、私が立ち往生した場所と達成しようとしているところを示すと信じているMREを添付しました。

if(!require('pacman')) {install.packages("pacman")} # Ensures that pacman is installed for auto-installation 
pacman::p_load(shiny, lipsum) # automatically installs and loads packages. 

ui <- fluidPage(# Sidebar with a slider input for font size 
    sidebarLayout(sidebarPanel(
     sliderInput("font_size", "Font Size:", min = 1, max = 200, value = 70 
     ) 
    ), 

    mainPanel(
     wellPanel(
      id = "textPanel", 
      style = "overflow-y:scroll; max-height: 50vh; font-size: 70%", 
      #style = paste0("overflow-y:scroll; max-height: 50vh; font-size: ", 
      # output$text_size,"70%"), 
     paste0(lipsum[2:10], collapse = ""))))) 

# Define server logic 
server <- function(input, output) { 
    output$text_size = renderText({input$font_size})} 

# Run the application 
shinyApp(ui = ui, server = server) 

答えて

3

あなたは、この場合font-sizeには、任意のCSSを変更するには、いくつかのJavaScriptコードを実行するためにshinyjsを使用することができます。

library(shiny) 
library(shinyjs) 

ui <- fluidPage( 
    shinyjs::useShinyjs(), 
    sidebarLayout(
    sidebarPanel(
     sliderInput("font_size", "Font Size:", min = 1, max = 200, value = 70) 
    ), 
    mainPanel(
     wellPanel(
     id = "textPanel", 
     style = "overflow-y:scroll; max-height: 50vh; font-size: 70%", 
     paste0("Hello", collapse = "")) 
    ) 
) 
) 

server <- function(input, output) { 
    observeEvent(input$font_size, { 
    runjs(paste0('$("#textPanel").css("font-size","', input$font_size, '%")')) 
    }) 
} 

shinyApp(ui = ui, server = server) 
関連する問題