R Shiny 中的 Reactive CSS 属性
Reactive CSS properties in R Shiny
我想用滑动条有选择地控制字体缩放。这可能吗?
我附上了一份 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)
您可以使用 shinyjs
到 运行 一些 JavaScript 代码来更改任何 CSS,在本例中是 font-size
.
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)
我想用滑动条有选择地控制字体缩放。这可能吗?
我附上了一份 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)
您可以使用 shinyjs
到 运行 一些 JavaScript 代码来更改任何 CSS,在本例中是 font-size
.
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)